linux installation postgresql

藏色散人
Release: 2019-11-22 10:28:39
forward
2855 people have browsed it

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
Copy after login

Initialize the database

sudo service postgresql initdb
 // 根据安装的版本确定postgresql 的版本
 eg: sudo service postgresql96 initdb
Copy after login

Start the database

sudo service postgresql start
Copy after login

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
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!