debian

Debian PostgreSQL网络连接设置

小樊
41
2025-11-07 11:44:32
栏目: 云计算

Debian PostgreSQL Network Connection Configuration

Configuring network access for PostgreSQL on Debian involves adjusting server settings, managing firewall rules, and ensuring secure connectivity. Below is a structured guide covering essential steps and best practices.

1. Install PostgreSQL

Before configuring network access, ensure PostgreSQL is installed on your Debian system. Run the following commands to update packages and install the server along with contrib utilities:

sudo apt update
sudo apt install postgresql postgresql-contrib

2. Configure postgresql.conf for Network Listening

The postgresql.conf file controls server listening behavior. Modify it to allow remote connections:

3. Adjust pg_hba.conf for Client Authentication

The pg_hba.conf file defines authentication rules for client connections. Add rules to permit remote access:

4. Restart PostgreSQL to Apply Configurations

After modifying postgresql.conf and pg_hba.conf, restart the PostgreSQL service to activate changes:

sudo systemctl restart postgresql

5. Configure Firewall Rules (UFW)

If UFW (Uncomplicated Firewall) is enabled, allow PostgreSQL’s default port (5432/tcp) to permit incoming connections:

sudo ufw allow 5432/tcp

6. Test Remote Connectivity

Use psql to verify remote access from another machine (replace server_ip, username, and database with your details):

psql -h server_ip -U username -d database

7. Optional: Enhance Security with SSL/TLS

For encrypted data transmission, configure SSL/TLS:

Key Notes for Production

By following these steps, you can securely configure network access for PostgreSQL on Debian, enabling remote connections while maintaining robust security practices.

0
看了该问题的人还看了