PG日常維護(一)
-
檢視錶結構
1.1SQL查詢
SELECT a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a.atttypmod AS lengthvar,a.attnotnull AS notnull FROM pg_class c,pg_attribute a,pg_type t WHERE c.relname='t1' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid postgres=# SELECT a.attnum,a.attname AS field,t.typname AS type,a.attlen AS length,a.atttypmod AS lengthvar,a.attnotnull AS notnull postgres-# FROM pg_class c,pg_attribute a,pg_type t postgres-# WHERE c.relname='t1' and a.attnum > 0 and a.attrelid = c.oid and a.atttypid = t.oid postgres-# ; attnum | field | type | length | lengthvar | notnull --------+-------+------+--------+-----------+--------- 1 | id | int4 | 4 | -1 | t
1.2快捷查詢
postgres-# \d+ t1; Table "public.t1" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description --------+---------+-----------+----------+---------+---------+--------------+------------- id | integer | | not null | | plain | 10000 | Indexes: "pk_t1_id" PRIMARY KEY, btree (id) "idx_t1_id" btree (id) Tablespace: "ts_data" Access method: heap Options: autovacuum_vacuum_cost_delay=10, autovacuum_vacuum_threshold=10000, autovacuum_analyze_threshold=10000, autovacuum_vacuum_cost_limit=10000, autovacuum_vacuum_scale_factor=0, autovacuum_analyze_scale_factor=0
2.檢視鎖定表
SELECT pg_class.relname AS table, pg_database.datname AS database, pid, mode, granted FROM pg_locks, pg_class, pg_database WHERE pg_locks.relation = pg_class.oid AND pg_locks.database = pg_database.oid; postgres=# SELECT pg_class.relname AS table, pg_database.datname AS database, pid, mode, granted postgres-# FROM pg_locks, pg_class, pg_database postgres-# WHERE pg_locks.relation = pg_class.oid postgres-# AND pg_locks.database = pg_database.oid; table | database | pid | mode | granted -----------------------------------+----------+-------+-----------------+--------- pg_class_tblspc_relfilenode_index | postgres | 34425 | AccessShareLock | t pg_class_relname_nsp_index | postgres | 34425 | AccessShareLock | t pg_class_oid_index | postgres | 34425 | AccessShareLock | t pg_class | postgres | 34425 | AccessShareLock | t pg_locks | postgres | 34425 | AccessShareLock | t (5 rows)
3.檢視資料庫大小
postgres=# SELECT pg_size_pretty(pg_database_size('POSTGRES')) As fulldbsize; fulldbsize ------------ 5151 MB (1 row)
4.快捷查詢
4.1檢視schema/owner關係 postgres-# \dn List of schemas Name | Owner --------------------+---------- information_schema | postgres pg_catalog | postgres pg_toast | postgres pg_toast_temp_1 | postgres public | postgres (5 rows) 4.2、檢視管理員使用者 postgres-# \du List of roles Role name | Attributes | Member of -------------+-----------------------------------+----------- gisplatform | | {} postgres | Superuser, Create role, Create DB | {} 4.3、檢視資料庫列表(dl)--l不是1 postgres-# \dl List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges -----------+----------+----------+-----------+-------------+----------------------- postgis | postgres | UTF8 | C | en_US.UTF-8 | postgres | postgres | UTF8 | C | en_US.UTF-8 | template0 | postgres | UTF8 | C | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | C | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (4 rows)
來自 “ ITPUB部落格 ” ,連結:https://blog.itpub.net/70038077/viewspace-3012493/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mc日常維護
- Oracle OGG日常維護Oracle
- OGG日常維護文件
- rac叢集日常維護命令
- 伺服器的日常維護方式伺服器
- 膝上型電腦日常維護的六個常識,筆記本日常維護小竅門筆記
- 伺服器維護日常需做哪些工作?伺服器
- 伺服器日常維護需注意哪些事項?伺服器
- DBA日常維護SQL指令碼_自己編寫的SQL指令碼
- SQL SERVER日常運維(一)SQLServer運維
- 集中管理伺服器軟體日常維護工具六款伺服器
- 黑龍江、鄭州、招聘、精通PHP的日常搭建維護PHP
- 史上最全近百條Oracle DBA日常維護SQL指令碼指令OracleSQL指令碼
- RAC日常運維運維
- 日常運維之TX鎖處理(一)運維
- Linux 系統日常運維 9 大技能,搞定 90% 日常運維Linux運維
- 運維日常工作運維
- 5S管理在辦公電腦日常維護中的應用
- Access資料庫日常維護和Access資料庫最佳化方法資料庫
- 跨境電商外貿企業的伺服器日常怎麼維護呢伺服器
- 三、日常運維指令碼編寫一些技巧運維指令碼
- TLB一致性維護
- SAP PM 入門系列11 - 一個維護通知單隻能建立一個維護訂單?
- MongoDB日常運維-02安裝MongoDB運維
- 在運維日常工作,"awk"的日常使用規範有哪些?運維
- 工業一體機的維護技巧
- Redis 創始人宣佈退居二線,不再進行專案的日常程式碼維護Redis
- MySQL 資料庫日常運維文件MySql資料庫運維
- 達夢資料庫日常運維資料庫運維
- Lync日常運維常用命令運維
- Postgresql日常運維-安裝(Linux)01SQL運維Linux
- Postgresql日常運維-安裝(Windows)02SQL運維Windows
- Redis日常運維-基礎認識Redis運維
- Redis日常運維-引數詳解Redis運維
- ORACLE OGG運維及日常監控Oracle運維
- Docker Swarm 日常運維命令筆記DockerSwarm運維筆記
- dolphindb dba一些常用的維護sqlSQL
- OceanBase 4.X 日常運維 常用SQL運維SQL