Home > Article > Operation and Maintenance > linux installation postgresql
The following column Linux Tutorial will introduce to you how to install postgresql on Linux. I hope it will be helpful to friends in need!
Install postgresql related packages through yum
sudo yum install -y postgresql postgresql-server postgresql96-devel postgresql-contrib postgresql-docs
Initialize the database
sudo service postgresql initdb // 根据安装的版本确定postgresql 的版本 eg: sudo service postgresql96 initdb
Start the database
sudo service postgresql start
Create users and data
// 首先登陆postgres 用户 sudo su postpres psql // 输入上条命令之后 进入psql ,就可以输入sql 语句 create user testuser with password 'testpwd'; // 创建数据库 create database testdb owner testuser; // 授予用户操作数据库的权限 grant all privileges on database testdb to testuser; \q 退出 // 修改配置文件,设置数据可以远程访问 sudo cd /var/lib/pgsql/data // 编辑文件 sudo vim postgresql.conf
Modify the file
Change listen_addresses = 'localhost' to listen_addresses = '*'
Modify the file pg_hba.conf
Add a line at the bottom of the file
host all 0.0.0.0/0 md5
// Restart the service
Note: Check whether the permissions of the data file are 700. If not, change it to 700. sudo chmod 700 /var/bin/data/
sudo service restart postgresql
Test connection
psql -h *.*.*.* -d testdb -U testuser
Possible errors
Peer authentication failed for user "postgres"
Solution
sudo vim /var/lib/pgsql/data/pg_hba.conf
host all all peer changed to
host all all trust
The above is the detailed content of linux installation postgresql. For more information, please follow other related articles on the PHP Chinese website!