加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 17:00:48 所属栏目:百科 来源:网络整理
导读:psql -h hostname or ip -p port [dbname] [username]-h 指定要连接数据库所在的主机名或者IP地址-p 指定连接的数据库端口,最后两个参数是数据库名和用户名。示例:[postgres@single ~]$ psql -h 186.168.100.13 -p 5432 testdb postgrespsql: could not co
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=#

 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读