PostgreSQL 14 Installation Guide on RHEL 8

不管现实多么惨不忍睹,都要持之以恒地相信,这只是黎明前短暂的黑暗而已。不要惶恐眼前的难关迈不过去,不要担心此刻的付出没有回报,别再花时间等待天降好运。真诚做人,努力做事!你想要的,岁月都会给你。PostgreSQL 14 Installation Guide on RHEL 8,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

PostgreSQL 14 Installation Guide on RHEL 8

Installation Instructions
Database version for this installation: PostgreSQL 14
Operating system: RHEL 8.6
Server Architecture: x86_64

System Configuration:

  1. Turn off the firewall
    sudo systemctl stop firewalld
    sudo systemctl disable firewalld

  2. Disable SeLinux
    sudo setenforce 0
    sudo sed -i ‘s/^SELINUX=enforcing/SELINUX=disabled/’ /etc/selinux/config

Installation and Startup of PostgreSQL 14
Install the PostgreSQL Yum repository:
sudo dnf install -y

Install the PostgreSQL 14 package:
sudo dnf install -y postgresql14-server

Initialize the PostgreSQL 14 database:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb

Set the PostgreSQL 14 service to start automatically at boot:
sudo systemctl enable postgresql-14

Start the PostgreSQL 14 service:
sudo systemctl start postgresql-14

Verify that PostgreSQL has been successfully installed and is running:
sudo systemctl status postgresql-14

PostgreSQL 14 Configuration Instructions:
After installation, the default files are:
The database software package installation files are located under the /usr/pgsql-14 directory
The data directory is located under /var/lib/pgsql/14/data
The configuration file is located in /var/lib/pgsql/14/data/postgresql.conf. This file contains many PostgreSQL configuration parameters, such as max_connections, shared_buffers, etc.
The authentication configuration file is located in /var/lib/pgsql/14/data/pg_hba.conf. This file contains the rules for PostgreSQL client authentication.
The service file is located in /usr/lib/systemd/system/postgresql-14.service. This file contains the startup parameters, environment variables, and other information for the PostgreSQL 14 service.
The log files are located under /var/lib/pgsql/14/data/log.

Set the superuser password
When PostgreSQL is installed, a superuser named postgres is automatically created. This user does not have a password set by default, so you can log in to the PostgreSQL service as the operating system user postgres.
Log in to the operating system as the postgres user.
su – postgres
Connect to the PostgreSQL service with the following command:
psql
In the PostgreSQL command line, change the password of the postgres user with the following command:
\password postgres
Exit the PostgreSQL command line:
\q

Configure Remote Access
Modify the pg_hba.conf file to configure the authentication rules for PostgreSQL. By default, PostgreSQL does not allow connections from external networks, so you need to modify the rules in pg_hba.conf to allow connections from specified IPs or IP ranges.
Allow all IP addresses to access
sed -i ‘$ a\host all all 0.0.0.0/0 md5’ /var/lib/pgsql/14/data/pg_hba.conf

After installing PostgreSQL, by default, it only accepts connection requests from localhost.
Edit the configuration file postgresql.conf, remove the preceding #, and change to listen_addresses =‘
sed -i “s/#listen_addresses = ‘localhost’/listen_addresses = ‘
’/g” /var/lib/pgsql/14/data/postgresql.conf

Set the maximum number of connections for PostgreSQL
The default is 100, you can set the maximum number of connections for PostgreSQL to 1000
sed -i ‘s/^#\smax_connections\s*=.*$/max_connections = 1000/’ /var/lib/pgsql/14/data/postgresql.conf
Restart the PostgreSQL 14 database to make the configuration take effect:
systemctl restart postgresql-14
Verify through SQL
SHOW max_connections;

Basic Usage
View all databases:
You can log in to the PostgreSQL database server and list existing databases with the following command:
Connect to PostgreSQL using the psql command:
$ psql -U postgres
Here the -U parameter specifies the username to connect with, which is the default administrator user postgres for PostgreSQL.
List all databases:
postgres=# \l
Here the meta-command \l is used in psql to list all existing databases.

View which users exist
psql -c ‘\du’
\du is a built-in command to display a list of created PostgreSQL users and their role attributes. This command outputs a table containing the user’s name, login permissions, superuser status, and whether it is a group role.

Create users, databases, and grant permissions
Create a user named myuser and a database named mydb
CREATE USER myuser WITH PASSWORD ‘111111’;
CREATE DATABASE mydb;
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
This will create a user named myuser with a password of 111111, and create a database named mydb, then grant all permissions to access the mydb database to the myuser user.

Login using this user
psql -d mydb -h 127.0.0.1 -p 5432 -U myuser
Here the newly created user myuser is used to log in, the database to connect to is mydb, the host to connect to is 127.0.0.1, and the port is 5432.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/181594.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!