最近由於工作需要,用到PostgreSQL,安裝的是64 位的PostgreSQL 9.6版本,現將基本的命令行指令總結一下,以備忘。
特別說明:Command line execute files are in the folder <PostgreSQL install dir>\bin
(1)菜單是最簡單的方法:
(2)指令創建:createdb -U postgres test
2、Restore db:pg_restore -d test -U postgres c:\\test.backup
or
psql -h localhost -U postgres -d dbname < C:\mydb.bak
3、delete db:dropdb -U postgres test
Sometimes the database couldn't be dropped because other sessions are using it. In this scenario, run the command in SQL Shell(psql) to close all the sessions:
SELECT
pg_terminate_backend(pg_stat_activity.pid)
FROM
pg_stat_activity
WHERE
datname=
'sm95'
AND
pid<>pg_backend_pid();
4、backup db:pg_dump -h ip -U postgres dbname > C:\mydb.bak
以上四部分是最常用的數據庫操作指令,數據庫建好之後,接下來就是在Server中配置數據庫,由於時間關係,該部分現在不作說明,後面如果時間允許,再更新博文將此部分加進去。
PostgreSQL安裝包下載:https://pan.baidu.com/s/1bFXlAQ