PostgreSQL学习第六篇--psql常用连接数据库的方法

前端之家收集整理的这篇文章主要介绍了PostgreSQL学习第六篇--psql常用连接数据库的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
psql -h <hostname or ip> -p <port> [dbname] [username]
-h 指定要连接数据库所在的主机名或者IP地址
-p 指定连接的数据库端口,最后两个参数是数据库名和用户名。
示例:
[postgres@single ~]$ psql -h 186.168.100.13 -p 5432 testdb postgres
psql: could not connect to server: Connection refused
        Is the server running on host "186.168.100.13" and accepting
        TCP/IP connections on port 5432?
[postgres@single ~]$ psql -h localhost -p 5432 testdb postgres
psql (9.6.1)
Type "help" for help.

[postgres@single pgdata]$ vi postgresql.conf

listen_addresses = '*'

[postgres@single pgdata]$ psql stop
psql: FATAL:  database "stop" does not exist
[postgres@single pgdata]$ pg_ctl stop
waiting for server to shut down.... done
server stopped
[postgres@single pgdata]$ pg_ctl start
server starting
[postgres@single pgdata]$ LOG:  database system was shut down at 2016-11-17 22:08:59 CST
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

 [postgres@single pgdata]$ psql -h 186.168.100.13 -p 5432 testdb postgres
FATAL:  no pg_hba.conf entry for host "186.168.100.13",user "postgres",database "testdb"
psql: FATAL:  no pg_hba.conf entry for host "186.168.100.13",database "testdb"

[postgres@single pgdata]$ vi pg_hba.conf
# IPv4 local connections:
host    all             all              186.168.100.13/32       trust 

[postgres@single pgdata]$ pg_ctl stop
LOG:  received fast shutdown request
LOG:  aborting any active transactions
LOG:  autovacuum launcher shutting down
LOG:  shutting down
waiting for server to shut down....LOG:  database system is shut down
 done
server stopped
[postgres@single pgdata]$
[postgres@single pgdata]$ pg_ctl start
server starting
[postgres@single pgdata]$ LOG:  database system was shut down at 2016-11-17 22:16:14 CST
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started

[postgres@single pgdata]$
[postgres@single pgdata]$ psql -h 186.168.100.13 -p 5432 testdb postgres
psql (9.6.1)
Type "help" for help.

testdb=#

 
原文链接:https://www.f2er.com/postgresql/194236.html

猜你在找的Postgre SQL相关文章