官方文档 https://www.postgresql.org/download/linux/redhat/
yum chart https://yum.postgresql.org/rpmchart/
RHEL7为例
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum install postgresql12 yum install postgresql12-server
RHEL8为例
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm dnf -qy module disable postgresql dnf install -y postgresql13 dnf install -y postgresql13-server
配置pg_stat_statement扩展
dnf install postgresql13-contrib # 编辑postgres.conf配置文件并重启数据库 shared_preload_libraries = 'pg_stat_statements' # Increase the max size of the query strings Postgres records track_activity_query_size = 2048 # Track statements generated by stored procedures as well pg_stat_statements.track = all # 默认抓取最大数量 5000 pg_stat_statements.max = 5000
安装pg_stat_statement扩展
create extension pg_stat_statements ; CREATE EXTENSION
安装之后进行初始化
$ pg_ctl init -D /pgdata The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /pgdata ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... America/New_York creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: /usr/pgsql-13/bin/pg_ctl -D /pgdata -l logfile start