Refer to the original link: http://www.cnblogs.com/sparkdev/p/5678874.html
Refer to the original link: https://www.cnblogs.com/andfly/p/6589488.html
Reference original link: https://www.jianshu.com/p/dda94c4ffd52
1. Install Postgresql in Ubuntu 16.04
sudo apt install postgresql
If everything goes well, you can see the following installation results:
Two, change the Postgres configuration
edit /etc/postgresql/9.5/main/postgresql.conf
将下面 listen_addresses = 'localhost'注释去掉并改为 listen_addresses = '*'
# - Connection Settings -
#listen_addresses = 'localhost'
# what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
...
将下面password_encryption = on 注释打开
#password_encryption = on
Switch users su - postgres
through psql
a command into the postgresql client
change password:
ALTER USER postgres PASSWORD '123456';
vim /etc/postgresql/9.5/main/pg_hba.conf
Modify host all all 192.168.1.0/24 md5
the ip, as follows:0.0.0.0/0
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 192.168.1.0/24 md5
# IPv6 local connections:
host all all ::1/128 trust
Three. Create a database and roles
Start the postgresql service before creating the database and role:
$ service postgresql restart 重启
$ service postgresql stop 停止
$ service postgresql start 启动
First switch the user to postgres (postgres is a system user created during the installation of postgresql. The role of this user is similar to the sa in sqlserver):
sudo -i -u postgres
Create the database kong:
createdb kong
Next, create the role kong, we implement it through the postgresql client:
psql
Type in the interactive command and press Enter:
CREATE USER kong; // 这个命令创建的role默认具有登录权限
Set a password for testuser:
\password kong // 按照提示输入密码
Set the owner of the database testdb to testuser:
ALTER DATABASE kong OWNER TO kong;
Use the \q command to log out of the current postgresql login, and then use the following command to log in to the newly created database:
psql -d kong -U kong -h 127.0.0.1 -W
Enter the password you just set for kong: