Sunday, 15 October 2023

Open port for PostgreSQL

=====================

- sudo nano /etc/postgresql/{version}/main/postgresql.conf

+ listen_addresses = '*'

// + port = 5433 (no needed)

- sudo nano /etc/postgresql/{version}/main/pg_hba.conf

+ host    all             all             [Your_IP_Can_Access]/32        md5 

- sudo service postgresql restart

- sudo ufw allow 5433/tcp
=====================
- access as root
$ sudo -u postgres psql
- show all dbs
$ \l

Connect to the PostgreSQL Database 
\c taximailinhdb;

Grant all privileges on the database:
GRANT ALL PRIVILEGES ON DATABASE hangchatgiagocdb TO hangchatgiagocuser;

Grant all privileges on all existing tables in the database: 
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO hangchatgiagocuser;

Grant all privileges on all sequences (if you are using sequences): 
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO hangchatgiagocuser;

Optionally, grant privileges on all future tables and sequences:
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO hangchatgiagocuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON SEQUENCES TO hangchatgiagocuser;

Step 3: Verify Permissions (Optional) 
\dp

No comments:

Post a Comment

Golang Advanced Interview Q&A