PostgreSql學習

PostgreSql學習(先mark一個)


1. PostgreSql與Oracle的區別

2. PostgreSql與MySql的區別

3. 使用PSql登陸數據庫

sudo su - postgres

psql my_db_name

4.使用psql執行一句sql命令

psql -c "select current_time";

5. 使用psql執行sql文件

psql mydb -f myscript.sql
6. 檢查數據庫版本

select version();

psql --version

7. 數據庫運行時間

select date_trunc('second', current_timestamp - pg_postmaster_start_time()) as uptime;
8. 數據庫啓動時間

select pg_postmaster_start_time();

9. 安裝路徑

ubuntu: /var/lib/postgresql/8.4

window:C:\Program Files\PostgreSQL\8.4

10. 數據庫消息日誌路徑

/var/log/postgresql

11. 列出有那些數據庫

select datname from pg_database;

postgres=# \x
Expanded display is on.

postgres=# select * from pg_database;

12.查詢一個數據庫中有多少張表

select count(*) from information_schema.tables
where table_schema not in ('information_schema','pg_catalog');

13. 查詢當前數據庫佔用多少空間

select pg_database_size(current_database());

14. 查詢所有數據庫的佔用空間

SELECT sum(pg_database_size(datname)) from pg_database;

15. 一個表的佔用空間

select pg_relation_size('accounts');

psql命令:\dt+ accounts

16. 查詢容量最大的10張表

select table_name, pg_relation_size(table_name) as size
from information_schema.tables
where table_schema not in ('information_schema','pg_catalog')
order by size desc
limit 10;

17.




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章