A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/PostgreSQL/snippets/pg-hba-conf-host.php below:

Website Navigation


Comprehensive Guide to pg_hba.conf Host Configuration

Comprehensive Guide to pg_hba.conf Host ConfigurationLast update on December 31 2024 13:03:32 (UTC/GMT +8 hours)

Configuring pg_hba.conf Entry for Host Connections

The pg_hba.conf file in PostgreSQL controls client authentication by defining who can connect, from where, and using which authentication method. Configuring a proper pg_hba.conf entry for a host is essential for allowing secure and specific connections to your PostgreSQL database.

Syntax:

Each line in pg_hba.conf follows this syntax:

type  database  user  address  auth-method  [auth-options]  

Parameters:

Examples

1. Allow Connections from a Specific Host

Code:

host  mydatabase  myuser  192.168.1.100/32  md5

Explanation:

2. Allow All Connections from a Subnet

Code:

host  all  all  10.10.0.0/16  scram-sha-256  

Explanation:

3. Trust Connections from Localhost

Code:

host  all  all  127.0.0.1/32  trust  

Explanation:

Editing the pg_hba.conf File

Advanced Usage

Using CIDR Notation

CIDR (Classless Inter-Domain Routing) allows specifying a range of IPs.

 
host  all  all  192.168.0.0/24  md5  

This entry permits all hosts in the 192.168.0.0 subnet to connect.

Combining SSL with Host Authentication

For secure connections, use the hostssl type.

 
hostssl  mydb  myuser  192.168.1.0/24  cert  

Common Errors and Troubleshooting

Precautions

All PostgreSQL Questions, Answers, and Code Snippets Collection.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4