1. PostgreSQL日常命令
# 常用SQL
查看当前用户: SELECT current_user;
查看所有用户: SELECT * FROM pg_user;
查看所有数据库: SELECT * FROM pg_database;
修改库的所有者: ALTER DATABASE mydb OWNER TO newowner;
修改表的所有者: ALTER TABLE tablename OWNER TO newowner;
如何连接到PostgreSQL数据库: psql -U <username> -d <database name> -h <host> -p <port>
# 常用命令
\c mydatabase myuser 以myuser用户连接到mydatabase
\l[+] [PATTERN] list databases
\dt[S+] [PATTERN] list tables
\d[S+] NAME describe table, view, sequence, or index
\dp [PATTERN] list table, view, and sequence access privileges
\df[anptw][S+] [FUNCPTRN [TYPEPTRN ...]] list [only agg/normal/procedure/trigger/window] functions
\x [on|off|auto] toggle expanded output (currently off)
\password [USERNAME] securely change the password for a user
# 基础知识
PostgreSQL的系统库: postgres, template0和template1