2019独角兽企业重金招聘Python工程师标准>>>
解决办法:
[root@www ~]# vi /var/lib/pgsql/data/pg_hba.conf
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all ident
# IPv4 local connections:
host all all 127.0.0.1/32 ident
host all all 10.10.46.1/24 md5 # 新添加
# IPv6 local connections:
host all all ::1/128 ident
[root@www ~]# vi /var/lib/pgsql/data/postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on; 移除注释
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart) 移除注释
#ssl_renegotiation_limit = 512MB # amount of data between renegotiations
password_encryption = on # 移除注释
3. 密码问题
在UNIX平台中安装PostgreSQL之后,PostgreSQL会在UNIX系统中创建一个名为“postgres”当用户。PostgreSQL的默认用户名和数据库也是“postgres”,
不过没有默认密码。
Yu@Coat ~ $ sudo su postgres #切换至postgres
postgres@Coat /home/Yu $ psql postgres#登入默认数据库
[sudo] passwordfor Yu:
psql (9.2.4)
Type "help" for help.
以上命令也可以简化为:
Yu@Coat ~ $ sudo -u postgres psql postgres
postgres=# \password postgres #给postgres用户设置密码
Enter new password:
Enter it again:
4. 访问数据库
1、列举数据库:\l
2、选择数据库:\c 数据库名
3、查看该某个库中的所有表:\dt
4、切换数据库:\c interface
5、查看某个库中的某个表结构:\d 表名
6、查看某个库中某个表的记录:select * from apps limit 1;
7、显示字符集:\encoding
8、退出psgl:\q
5.启停PostgreSQL
[postgres@localhost pgsql]$ pg_ctl start -D /mydata/pgdata/
waiting for server to start....2018-02-20 00:52:03.616 CST [38915] LOG: listening on IPv6 address "::1", port 5432
2018-02-20 00:52:03.616 CST [38915] LOG: listening on IPv4 address "127.0.0.1", port 5432
2018-02-20 00:52:03.619 CST [38915] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2018-02-20 00:52:03.689 CST [38916] LOG: database system was shut down at 2018-02-20 00:44:56 CST
2018-02-20 00:52:03.692 CST [38915] LOG: database system is ready to accept connections
doneserver started
[postgres@localhost pgsql]$ pg_ctl stop -D /mydata/pgdata/备注:
可以在命令后增加 [-m SHUTDOWN-MODE],用来控制数据库的停止方法;SHUTDOWN-MODE有以下三种:
smart:等所有的连接终止后,关闭数据库。如果客户端连接不终止,则无法关闭数据库。
fast (PostgreSQL10.X默认):快速关闭数据库,断开客户端的连接,让已有的事物回滚,然后正常关闭数据库。
相当于Oracle数据库关闭时的immediate(adj. 立即的)模式。
immediate:不完整的关闭数据库,相当于kill数据库进程,下次启动数据库需要进行恢复。相当于Oracle数据库关闭时的abort模式。
其中,比较常用的是fast模式。