【PSQL16】Ident authentication failed for user “postgres”

以下のようなエラーが出る時
$ python3 migration.py
Traceback (most recent call last):
File “/home/ec2-user/cmc_test/assets/migration.py”, line 8, in
connection = psycopg2.connect(
File “/home/ec2-user/cmc_test/venv/lib64/python3.9/site-packages/psycopg2/__init__.py”, line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at “localhost” (127.0.0.1), port 5432 failed: FATAL: Ident authentication failed for user “postgres”

sudo vi /var/lib/pgsql/data/pg_hba.conf
identからtrustに変更します。

# IPv4 local connections:
# host    all             all             127.0.0.1/32            ident
host    all             all             127.0.0.1/32            trust

$ sudo service postgresql restart
$ python3 migration.py

ふぅ~