当前位置:网站首页>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
边栏推荐
- Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
- KBU1510-ASEMI电源专用15A整流桥KBU1510
- Resource create package method
- After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
- JSON introduction and JS parsing JSON
- Leetcode-543. Diameter of Binary Tree
- 在线直播系统源码,使用ValueAnimator实现view放大缩小动画效果
- Live broadcast platform source code, foldable menu bar
- [2022 ACTF]web题目复现
- [OBS] win capture requires winrt
猜你喜欢
为什么要了解现货黄金走势?
Iterable、Collection、List 的常见方法签名以及含义
ASEMI整流桥RS210参数,RS210规格,RS210封装
Outsourcing for four years, abandoned
[Stanford Jiwang cs144 project] lab3: tcpsender
My ideal software tester development status
Why should we understand the trend of spot gold?
Make a bat file for cleaning system garbage
[2022 actf] Web Topic recurrence
Hands on deep learning (IV) -- convolutional neural network CNN
随机推荐
为什么要了解现货黄金走势?
After 95, the CV engineer posted the payroll and made up this. It's really fragrant
Outsourcing for three years, abandoned
[P2P] local packet capturing
微信小程序中使用wx.showToast()进行界面交互
JS plot flot application - simple curve
Mutual conversion between InputStream, int, shot, long and byte arrays
Simple example of ros2 planning system plansys2
buuctf misc USB
[Stanford Jiwang cs144 project] lab3: tcpsender
Button wizard collection learning - mineral medicine collection and running map
Outsourcing for four years, abandoned
The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)
基于Flask搭建个人网站
【斯坦福计网CS144项目】Lab4: TCPConnection
Rxjs - observable doesn't complete when an error occurs - rxjs - observable doesn't complete when an error occurs
【斯坦福计网CS144项目】Lab3: TCPSender
leetcode:105. 从前序与中序遍历序列构造二叉树
Live online system source code, using valueanimator to achieve view zoom in and out animation effect
[webrtc] m98 Screen and Window Collection