Ubuntu 18.04 PostgreSQL 11 apt 默认安装某些问题解析

首先默认安装软件(本文以PostgreSQL 11.1为例,其他版本类似)。

sudo apt install postgresql-11

等待软件自动安装并完成配置,启动服务。

服务状态如下:

vmware@vmware-virtual-machine:~$ service postgresql status
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Thu 2018-12-13 17:16:01 CST; 24min ago
 Main PID: 19530 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 2289)
   CGroup: /system.slice/postgresql.service

12月 13 17:16:01 vmware-virtual-machine systemd[1]: Starting PostgreSQL RDBMS...
12月 13 17:16:01 vmware-virtual-machine systemd[1]: Started PostgreSQL RDBMS.
vmware@vmware-virtual-machine:~$ 

安装完成后,默认条件下:

(1)创建 "postgres" Linux 用户

(2)创建 "postgres" 未知密码默认数据库管理员账号

(3)创建 "postgres" 数据库

部分默认配置文件夹如下

#配置文件
vmware@vmware-virtual-machine:~$ ls /etc/postgresql/11/main
conf.d  environment  pg_ctl.conf  pg_hba.conf  pg_ident.conf  postgresql.conf  start.conf
#数据文件
vmware@vmware-virtual-machine:~$ sudo ls /var/lib/postgresql/11/main/
base	pg_commit_ts  pg_logical    pg_notify	 pg_serial     pg_stat	    pg_subtrans  pg_twophase  pg_wal   postgresql.auto.conf  postmaster.pid
global	pg_dynshmem   pg_multixact  pg_replslot  pg_snapshots  pg_stat_tmp  pg_tblspc	 PG_VERSION   pg_xact  postmaster.opts
vmware@vmware-virtual-machine:~$

登录PostgreSQL 数据库(两种方法)。

#方法1
vmware@vmware-virtual-machine:~$ sudo -u postgres psql
psql (11.1 (Ubuntu 11.1-1.pgdg18.04+1))
输入 "help" 来获取帮助信息.

postgres=# \l
                                     数据库列表
   名称    |  拥有者  | 字元编码 |  校对规则   |    Ctype    |       存取权限        
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 行记录)

postgres=# \q
#方法2
vmware@vmware-virtual-machine:~$ sudo -i
root@vmware-virtual-machine:~# su - postgres 
postgres@vmware-virtual-machine:~$ psql
psql (11.1 (Ubuntu 11.1-1.pgdg18.04+1))
输入 "help" 来获取帮助信息.

postgres=# 

数据库默认本机可以访问,默认监听本机端口。现在修改数据库内网访问限制。(本文增加192.168.0.1/16网段;0.0.0.0代表所有主机,不推荐)

#开启监听
 53 #------------------------------------------------------------------------------
 54 # CONNECTIONS AND AUTHENTICATION
 55 #------------------------------------------------------------------------------
 56 
 57 # - Connection Settings -
 58 listen_addresses='*'
#主机连接信息
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             192.168.0.1/16          md5

修改完毕配置文件以后记得reload配置文件。

root@vmware-virtual-machine:~# su - postgres 
postgres@vmware-virtual-machine:~$ psql
psql (11.1 (Ubuntu 11.1-1.pgdg18.04+1))
输入 "help" 来获取帮助信息.

postgres=#
postgres=# SELECT pg_reload_conf();
 pg_reload_conf 
----------------
 t
(1 行记录)

postgres=# 

需要注意,自动安装数据库管理员密码未知,需要手动修改。修改数据库密码为123456。

root@vmware-virtual-machine:~# su - postgres 
postgres@vmware-virtual-machine:~$ psql
psql (11.1 (Ubuntu 11.1-1.pgdg18.04+1))
输入 "help" 来获取帮助信息.

postgres=# ALTER USER postgres WITH PASSWORD '123456';
ALTER ROLE
postgres=# 

测试数据库连接成功。(本文以Microsoft Visual Studio 安装好数据库驱动为例。)

4e2ef25fce33a58dc2c579594cf27511010.jpg

转载于:https://my.oschina.net/u/1011130/blog/2988178

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值