当前位置:网站首页>PostgreSQL basic introduction and deployment
PostgreSQL basic introduction and deployment
2022-06-12 03:24:00 【Hongyu】
postgresql Basic introduction and deployment
For the database , As IT Technicians are no strangers , I have used it directly mysql and sqlserver database , I have also studied systematically oracle database , And for postgresql database , Only in gis I have heard of it in the field and foreign enterprises , And that's why I'm interested .
Learn by sorting out relevant online learning materials , And in the local build environment postgresql Actual setup, deployment and brief use , Record here , In order to continue in-depth study in the follow-up , It also provides reference for latecomers , There are unavoidable omissions in the text , Readers are expected to make corrections , Thank you for !
1. Basic introduction
1.1 essential information
PostgreSQL Is a powerful open source database system . After a 15 More than years of active development and continuous improvement ,PostgreSQL Under reliability 、 stability 、 Data consistency has won a high reputation in the industry . at present PostgreSQL It can run on all mainstream operating systems , Include Linux、Unix and Windows.
PostgreSQL Is a fully transactional security database , Support rich data types ( Such as JSON and JSONB type 、 An array type ) And custom types .PostgreSQL The database provides rich interfaces , It's easy to extend its functions , If you can GiST Implement your own index type under the framework , Support use C Language to write custom functions 、 trigger , It also supports writing custom functions in popular programming languages .PL/Perl Provides the use of Perl Language to write custom functions , Of course, PL/Python、PL/Java、PL/Tcl etc. .
As an enterprise database ,PostgreSQL Take pride in all the advanced functions it has , Like multi version concurrency control (MVCC)、 Restore... In time (PITR)、 Table space 、 Asynchronous replication 、 Nested transactions 、 Online hot standby 、 Planning and optimization of complex queries and pre writing logs for fault tolerance . It supports international character sets 、 Multibyte encoding and support for sorting in local languages 、 Case handling and formatting operations . It also has full high scalability in the large amount of data it can manage and the large amount of users it allows for concurrent access time .
1.2 advantage
PostgreSQL Database has the following advantages :
PostgreSQL Database is the most powerful open source database at present , It is closest to the industrial standard SQL92 Query language of , At least it has SQL:2011 What is required in the standard 179 Of the main functions 160 term ( notes : At present, no database management system can fully realize SQL:2011 All the main functions in the standard ).
Stable and reliable :PostgreSQL It is the only open source database that can achieve zero data loss . At present, it is reported that some banks at home and abroad use PostgreSQL database .
Open source saves money : PostgreSQL The database is open source 、 Free of charge , And it uses classes BSD agreement , There are basically no restrictions on use and secondary development .
There is broad support for :PostgreSQL The database supports a large number of mainstream development languages , Include C、C++、Perl、Python、Java、Tcl as well as PHP etc. .
PostgreSQL The community is active :PostgreSQL Basically every 3 A patch version will be released next month , This means known Bug It will be repaired soon , The requirements of application scenarios will also be responded in time .
2. contrast mysql and oracle
2.1 Postgresql VS Oracle
Oracle Database is the most powerful commercial database at present ,PostgreSQL Is the most powerful open source database .
PostgreSQL And Oracle The difference is that ,PostgreSQL There are more features that support Internet features . Such as PostgreSQL Data types support network address types 、XML type 、JSON type 、UUID Type and array type , And there are powerful regular expression functions , Such as where Regular expressions can be used in conditions to match , You can also use Python、Perl And other languages to write stored procedures . in addition ,PostgreSQL Smaller .PostgreSQL It can run perfectly on a machine with very little memory , If in 512MB In the virtual machine , and Oracle The database should basically be in the number GB Can be run in the virtual machine .Oracle There are several installation packages GB Above level , and PostgreSQL There are only dozens of installation packages MB size .PostgreSQL It can be easily installed in any environment .Oracle The time taken for database installation is at the hour level , and PostgreSQL The installation can be completed at the minute level .
2.2 Postgresql VS Mysql
Postgresql and Mysql Are open source databases .
PostgreSQL It has the following advantages .
Powerful : Support all mainstream multi table join query methods , Such as “Hash JOIN”“Sort Merge JOIN” etc. ; Field types also support array types , Even some business functions don't need to write code to implement , The problem can be solved by directly using the functions of the database .
Performance optimization tools and metrics are informative :PostgreSQL There are a lot of performance views in the database , Can easily locate the problem ( For example, you can see what is being executed SQL, You can see who is waiting through the lock view , And which records are locked ).PostgreSQL A special architecture and process are designed to collect performance data , Existing physics I/O Statistics in the field , There are also table scanning and index scanning performance data .
Good online operation function :PostgreSQL When adding a null value column , In essence, it just defines the columns in the system table , There is no need to update the physical structure , This makes PostgreSQL It can be completed instantly when adding columns .PostgreSQL It also supports online indexing , During the index creation process, the update operation can be unlocked .
from PostgreSQL9.1 Start , Support for synchronous replication (synchronous replication) function , adopt Master and Slave Replication between can achieve a high availability solution with zero data loss .
You can easily write plug-ins to extend PostgreSQL Database functionality : Support the new functions of mobile Internet , Such as spatial index
If the data access of the application is simple , So the back end uses MySQL It's also very suitable . But if the application is complex , And don't want to consume too much development resources , that PostgreSQL It's a wise choice .
3. Installation and deployment
3.1 Installation environment
Server environment :centos7
postgresql edition :postgresql-14.0
3.2 Installation steps
- Download installation package

- Decompress and compile
yum -y install gcc gcc-c++ readline-devel zlib-devel
tar -zvxf postgresql-14.0.tar.gz
cd postgresql-14.0
./configure
make && make install
/usr/local/ The catalogue will produce pgsql Catalog
- Users and permissions
useradd postgres
chown -R postgres:postgres pgsql/
- Initialize database
Get into bin Catalog
su postgres
./initdb /usr/local/pgsql/data
- start-up
./pg_ctl -D /usr/local/pgsql/data -l logfile start
# Turn on
/home/postgres/pgsql/bin/pg_ctl -D /home/postgres/data/ -l logfile start
# Check the status
/home/postgres/pgsql/bin/pg_ctl -D /home/postgres/data/ -l logfile status
# stop it
/home/postgres/pgsql/bin/pg_ctl -D /home/postgres/data/ -l logfile stop


- Modify the configuration
After initialization, in postgresql Can see the generated data directory data And the relevant data and configuration files of the directory ,pg_hba.conf and postgresql.conf,
One is access control configuration (127.0.0.1 Change to a trusted client ip The network segment enables it to access remotely ),
One is postgresql Master profile (listen_address=localhost Change the asterisk to make it monitor the whole network )
pg_hba.conf Configure the authentication methods allowed by the server in , Add the following line .
TYPE DATABASE USER CIDR-ADDRESS METHOD
host all all 0.0.0.0/0 password
postgresql.conf Edit or add the following line , send PostgreSQL Can accept from any IP Connection request for , Open the port , Turned out to be The annotations
listen_addresses = '*'
port = 5432
- restart pgsql
./pg_ctl -D /usr/local/pgsql/data/ -l logfile restart

- Login and password change
./psql
ALTER USER postgres WITH PASSWORD '123456';
psql -d postgres -p 5432 -U postgres -h Localhost
- navicat Remote connection successful

4. Boot from boot
- Find the startup script under the installation package
postgresql-14.0/contrib/start-scripts/linux
- Copy startup script
cp postgresql-14.0/contrib/start-scripts/linux /etc/init.d/postgresql
- Modify script configuration
# Installation prefix
prefix=/usr/local/pgsql
# Data directory
PGDATA="/usr/local/pgsql/data"
# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=postgres
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
- Add execution permission
chmod a+x /etc/init.d/postgresql
- Register the boot auto start
chkconfig Command to register the script as startup :
chkconfig --add postgresql
Restart validation
ps -ef|grep postgresql


5. pgadmin client
https://www.pgadmin.org/download/

6. Reference material
https://www.postgresql.org/
https://www.pgadmin.org/
https://blog.51cto.com/u_15289334/3321664
https://blog.csdn.net/Victory_Lei/article/details/121414749
边栏推荐
- TCP three handshakes and four waves
- MySQL创建用户并授权
- mysql/oracle 以唯一时间为分界,小于等于该时间求和,大于该时间求和
- Wechat applet project example - Fitness calculator
- central limit theorem
- In 2022, why is there a market for Shanzhai products?
- ics-07
- Youcans' opencv lesson - 10 Image restoration and reconstruction
- Geforce GTX 2050/2080/3090/a6000 auto install NVIDIA graphics driver
- Key points of code neatness (III)
猜你喜欢

Calculus review 2

KV storage separation principle and performance evaluation of nebula graph

Requirements and business model innovation - Requirements 7- user requirements acquisition based on use case / scenario model
![[point cloud compression] variable image compression with a scale hyperprior](/img/d4/4084f64d20c8e622cddef2310d3b6c.png)
[point cloud compression] variable image compression with a scale hyperprior
![[C language] dynamic memory allocation](/img/ac/ba3882c76f93dde0ab0d5294c5b6d9.jpg)
[C language] dynamic memory allocation

微信小程序项目实例——我有一支画笔(画画)

Sparse tensor based point cloud attribute compression

微信小程序項目實例——體質計算器

分数大小的比较

tcp 三次握手与四次挥手
随机推荐
简单的数据库连接示例
Inverted string - two solutions
Sequence list and linked list - primary level
Demand and business model innovation - demand 9- prototype
What is the core of Web3?
2022 communication industry ultimate Exhibition Guide
Comparaison de la taille des fractions
Special materials | household appliances, white electricity, kitchen electricity
消息队列概述
laravel 8 选用 jwt 进行接口验证
errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000
[DFS "want" or "don't"] seek subsets; Seeking combination
Leetcode 6[finding rules] Z-transform the leetcode path of heroding
central limit theorem
利用ssh公钥传输文件
In 2022, don't you know the difference between arrow function and ordinary function?
【点云压缩】Variational Image Compression with A Scale Hyperprior
2020-12-07
string manipulation:
Application of ankery anti shake electric products in a chemical project in Hebei