当前位置:网站首页>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
边栏推荐
- Is the test cycle compressed? Teach you 9 ways to deal with it
- L'externalisation a duré trois ans.
- 自定义类加载器加载网络Class
- After the interview, the interviewer roast in the circle of friends
- Value sequence (subsequence contribution problem)
- The metauniverse of the platofarm farm continues to expand, with Dao governance as the core
- Leetcode-226. Invert Binary Tree
- What are the positions of communication equipment manufacturers?
- [mathematical notes] radian
- Live broadcast platform source code, foldable menu bar
猜你喜欢
探索Cassandra的去中心化分布式架构
Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
Flutter riverpod is comprehensively and deeply analyzed. Why is it officially recommended?
4、 High performance go language release optimization and landing practice youth training camp notes
海思芯片(hi3516dv300)uboot镜像生成过程详解
nacos
After 95, Alibaba P7 published the payroll: it's really fragrant to make up this
Asemi rectifier bridge rs210 parameters, rs210 specifications, rs210 package
A bit of knowledge - about Apple Certified MFI
Talk about seven ways to realize asynchronous programming
随机推荐
KBU1510-ASEMI电源专用15A整流桥KBU1510
Determining the full type of a variable
海思芯片(hi3516dv300)uboot镜像生成过程详解
Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
解决:Could NOT find KF5 (missing: CoreAddons DBusAddons DocTools XmlGui)
【obs】win-capture需要winrt
[GUET-CTF2019]虚假的压缩包
vus.SSR在asynData函数中请求数据的注意事项
Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
Few-Shot Learning && Meta Learning:小样本学习原理和Siamese网络结构(一)
Button wizard script learning - about tmall grabbing red envelopes
Tongda injection 0day
leanote私有云笔记搭建
Make a bat file for cleaning system garbage
[ANSYS] learning experience of APDL finite element analysis
Value sequence (subsequence contribution problem)
解决问题:Unable to connect to Redis
Resource create package method
基于Flask搭建个人网站