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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle RAC 日常維護Oracle
- RAC日常維護命令
- Oracle OGG日常維護Oracle
- Gerrit日常維護記錄
- 【MHA】mha日常維護命令
- DBA日常維護SQL整理SQL
- DataGuard 日常維護命令整理
- 針對oracle日常維護Oracle
- 自動儲存管理ASM日常維護(一)ASM
- rac叢集日常維護命令
- ORACLE DG 日常維護常用SQLOracleSQL
- DBA日常維護SQL指令碼SQL指令碼
- 物理standby database的日常維護Database
- OGG goldengate 日常維護Go
- IBM AIX日常維護命令IBMAI
- 【轉】ORACLE CRS日常維護命令Oracle
- Oracle資料庫日常維護Oracle資料庫
- Oracle DBA 日常維護手冊Oracle
- VMware日常維護工作內容
- Oracle RAC日常基本維護命令Oracle
- 伺服器的日常維護方式伺服器
- EBS DBA日常維護使用的sqlSQL
- nginx日常維護常用命令Nginx
- Dataguard日常維護及故障解決
- 【轉】Oracle RAC日常基本維護命令Oracle
- 收集oracle日常維護的工作命令Oracle
- 膝上型電腦日常維護的六個常識,筆記本日常維護小竅門筆記
- linux中oracle的日常維護命令LinuxOracle
- 電腦日常保養維護指南(轉)
- 伺服器維護日常需做哪些工作?伺服器
- 紅帽作業系統日常安全維護作業系統
- MS SQL 日常維護管理常用指令碼(下)SQL指令碼
- 【轉】Oracle資料庫日常維護手冊Oracle資料庫
- Oracle資料庫日常維護手冊 (zt)Oracle資料庫
- MS SQL 日常維護管理常用指令碼(上)SQL指令碼
- 伺服器日常維護需注意哪些事項?伺服器
- Oracle ERP系統日常維護和巡檢Oracle
- DBA日常維護SQL指令碼_自己編寫的SQL指令碼