sudo apt-get update
sudo apt-get install postgresql
sudo -u postgres psql
其中,sudo -u postgres 是使用postgres 用户登录的意思
PostgreSQL数据默认会创建一个postgres的数据库用户作为数据库的管理员,密码是随机的
- 修改postgres数据库用户的密码为123456
ALTER USER postgres WITH PASSWORD '123456';
\q
- 修改ubuntu操作系统的postgres用户的密码(密码要与数据库用户postgres的密码相同)
切换到root用户
su root
删除PostgreSQL用户密码
sudo passwd -d postgres
设置PostgreSQL系统用户的密码
sudo -u postgres passwd
sudo vim /etc/postgresql/10/main/postgresql.conf
#listen_addresses = ‘localhost‘ --> listen_addresses = ‘*‘
取消调注释
password_encryption = md5
sudo vim /etc/postgresql/10/main/pg_hba.conf
添加
host all all 0.0.0.0 0.0.0.0 md5
重启服务
sudo /etc/init.d/postgresql restart
5432口的防火墙设置允许通过(PostgreSQL的默认端口是5432)
sudo iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
create user "blog" with password '123456' nocreatedb;
create database "blog" with owner = "blog";
sudo -u postgres createuser -D -P test1
sudo -u postgres createdb -O test1 test1
\q
\l
\dt
drop database test1;
drop user test1;