Command
shell:
sudo -u postgres createuser --superuser dbuser
sudo -u postgres createdb -O dbuser exampledb
psql : postgres console
psql -U postgres
psql -U postgres -d postgres -h 127.0.0.1 -p 5432
psql -U postgres -f file.sql
postgres console:
\h 查看SQL命令的解释,比如\h select。
\? 查看psql命令列表。
\l 列出所有数据库。
\c [database_name] 连接其他数据库。
\d 列出当前数据库的所有表格。
\d [table_name] 列出某一张表格的结构。
\du 列出所有用户。
\e 打开文本编辑器。
\conninfo 列出当前数据库和连接的信息。
\password user 修改密码
\q 退出
CREATE USER dbuser WITH PASSWORD 'password';
CREATE DATABASE exampledb OWNER dbuser;
GRANT ALL PRIVILEGES ON DATABASE exampledb to dbuser;
Error
1. GUI client connection
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432?
Solution:
1. 修改pg_hba.conf
[root@c9t21622 bin]# vim /var/lib/pgsql/9.4/data/pg_hba.conf
添加:
host all all 15.107.13.42/23 trust
或修改
#host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
2. 修改postgresql.conf (localhost -> *)
[root@c9t21622 bin]# vim /var/lib/pgsql/9.4/data/postgresql.conf
57 # - Connection Settings -
58 listen_addresses = '*'