当前位置:网站首页>Installing postgresql11 database under centos7
Installing postgresql11 database under centos7
2022-07-07 07:48:00 【Guardian stone】
1. obtain PG Of Repo file
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
We can know through the following command repo The installation directory of the file :
[[email protected] ~]# rpm -ql pgdg-redhat-repo
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG
/etc/yum.repos.d/pgdg-redhat-all.repo
pgdg-redhat-all.repo File for yum Remote installation provides PostgreSQL Remote installation source for .
2. install PostgreSQL Client and server
yum install postgresql11 postgresql11-server
All the way y Key will do .
3. initialization
/usr/pgsql-11/bin/postgresql-11-setup initdb
And then postgresql Service join self start and start PostgreSQL
systemctl enable postgresql-11
systemctl start postgresql-11
4. permissions
installation is complete PostgreSQL After the client , Will be for Linux establish postgres Account , Let's set the password for this account first .
passwd postgres
New password:
Retype new password:
Input separately “ Your password ”
next , Linux from root Downgrade to postgres The user login shell terminal ( perhaps SSH), adopt pgsql Order to enter PG Console , Set up PG Super tube user postgres Password .
su postgres
psql
alter user postgres with password ' Your password ';
exit
5. modify PG Related configuration files , Set external access control rules
First configuration postgresql.conf file , to open up PG Network access port .
vi /var/lib/pgsql/11/data/postgresql.conf
modify listen_addresses The value of is ‘*’:
listen_addresses = '*' # what IP address(es) to listen on;
Next configuration pg_hba.conf file , Fine grained control PG Service access and PG Master slave copied IP paragraph
vi /var/lib/pgsql/11/data/pg_hba.conf
Focus on the following configuration line. The end is “md5” Modification of configuration items :
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.83.0/16 md5
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all md5
host replication all 127.0.0.1/32 md5
host replication all 192.168.83.0/24 md5
host replication all ::1/128 ident
In the above configuration PostgreSQL Access to database services IP Configuration is 192.168.83.0/16 , The mask bit is 16, Then you can visit IP Segment is 192.168.0.1~192.168.255.254.
PostgreSQL Replication of services (replication) visit IP Configuration is 192.168.83.0/24, The mask bit is 24, Then you can visit IP Segment is 192.168.83.1~192.168.83.254.
notes : If you want to let go completely PostgreSQL Access control , Only need to 192.168.83.0/16 Change it to 0.0.0.0/0.
Finally, we need to return root user , restart PG service , Make the configuration work .
systemctl restart postgresql-11
6. Other configuration
(1) Linux Downgrade login again postgres user , And then use pgsql Order to enter PG Console , Let's see. PostgreSQL Is it a Chinese environment .
select * from pg_database;
We focus on datcollate,datctype Two , See if it is zh_CN.UTF-8
postgres=# select * from pg_database;
datname | datdba | encoding | datcollate | datctype | datistemplate | datallowconn | datconnlimit | datlastsysoid | datfrozenxid | datminmxid | dattablespace |
datacl
-----------+--------+----------+-------------+-------------+---------------+--------------+--------------+---------------+--------------+------------+---------------+--------------
-----------------------
postgres | 10 | 6 | zh_CN.UTF-8 | zh_CN.UTF-8 | f | t | -1 | 13880 | 561 | 1 | 1663 |
template1 | 10 | 6 | zh_CN.UTF-8 | zh_CN.UTF-8 | t | t | -1 | 13880 | 561 | 1 | 1663 | {=c/postgres,
postgres=CTc/postgres}
template0 | 10 | 6 | zh_CN.UTF-8 | zh_CN.UTF-8 | t | f | -1 | 13880 | 561 | 1 | 1663 | {=c/postgres,
postgres=CTc/postgres}
(3 rows)
If not , perform SQL modify :
update pg_database set datcollate='zh_CN.UTF-8',datctype='zh_CN.UTF-8';
(2) Give Way postgres Users can reload pg_hba.conf The configuration file :
Return root user , Execute the following commands continuously :
echo 'export PGDATA=/var/lib/pgsql/11/data' >> /etc/profile
source /etc/profile
PGDATA The environment variables have been set globally .
We are demoted to postgres user , If to modify pg_hba.conf The configuration file , Direct command execution :
/usr/pgsql-11/bin/pg_ctl reload
You can reload pg_hba.conf The configuration file , Without having to restart postgresql-11 service .
7.PostgreSQL A brief description of the command
(1). Create database , Be sure to specify roles (PG Mainly controlled by roles ).
for example , We first pass pgsql, Used postgres Super user login :
create role health login password ' Your password ';
create database health_db with owner= health;
We created roles “health”, Then create the database “health_db” When , You need to specify the owner of this database as “health”.
Corresponding delete database and role commands :
drop database health_db;
drop role health;
When it comes to comprehensive operation “health_db” When it comes to databases , Please exit PG Console , Enter into Linux Of postgres User login status , Reuse “health” Character landing PG Console :
psql -U health -d health_db
We can use the following command :
\l perhaps \l databaseName view the database
\d perhaps \d tableName Look at the data sheet
\du To view the user
\dnS View mode
\c databaseName Switch database
边栏推荐
- About some details of final, I have something to say - learn about final CSDN creation clock out from the memory model
- Solution: could not find kf5 (missing: coreaddons dbusaddons doctools xmlgui)
- A bit of knowledge - about Apple Certified MFI
- Hands on deep learning (IV) -- convolutional neural network CNN
- 2022-07-06: will the following go language codes be panic? A: Meeting; B: No. package main import “C“ func main() { var ch chan struct
- Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
- leanote私有云笔记搭建
- 【webrtc】m98 screen和window采集
- 1、 Go knowledge check and remedy + practical course notes youth training camp notes
- Why is the row of SQL_ The ranking returned by number is 1
猜你喜欢
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
1142_ SiCp learning notes_ Functions and processes created by functions_ Linear recursion and iteration
为什么要了解现货黄金走势?
[Stanford Jiwang cs144 project] lab3: tcpsender
[2022 ACTF]web题目复现
My ideal software tester development status
IO流 file
Iterable、Collection、List 的常见方法签名以及含义
Idea add class annotation template and method template
Tencent's one-day life
随机推荐
[experience sharing] how to expand the cloud service icon for Visio
Codeforces Global Round 19
1、 Go knowledge check and remedy + practical course notes youth training camp notes
【经验分享】如何为visio扩展云服务图标
Solution: could not find kf5 (missing: coreaddons dbusaddons doctools xmlgui)
Rxjs - observable doesn't complete when an error occurs - rxjs - observable doesn't complete when an error occurs
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
Resource create package method
毕设-基于SSM大学生兼职平台系统
Info | webrtc M97 update
Operation suggestions for today's spot Silver
在线直播系统源码,使用ValueAnimator实现view放大缩小动画效果
Six methods of flattening arrays with JS
About some details of final, I have something to say - learn about final CSDN creation clock out from the memory model
Idea add class annotation template and method template
Common method signatures and meanings of Iterable, collection and list
Route jump in wechat applet
242. Bipartite graph determination
BGP experiment (1)
pytest+allure+jenkins环境--填坑完毕