Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.88 KB

File metadata and controls

59 lines (41 loc) · 1.88 KB

POSTGRE SQL Hints

1. Check if <db_name> exists

Method 1: Using psql (Best for checking existence)

This method lists all databases and pipes the output to grep to find your specific database name.

psql -l | grep -qw your_db_name && echo "Database 'your_db_name' exists." || echo "Database 'your_db_name' does not exist."

in dev mode: ```bash psql -U postgres -l | grep -qw task_api_db && echo "Database 'task_api_db' exists." || echo "Database 'task_api_db' does not exist."


#### Method 2: Using pg_isready (For connection status) 
This utility checks if the server is accepting connections for a specific database. 
```bash
pg_isready -d your_db_name -q && echo "Server ready for 'your_db_name'." || echo "Server not ready or DB not found."

in dev mode:

pg_isready -d task_api_db -q && echo "Server ready for 'task_api_db'." || echo "Server not ready or DB not found."

2. Use PostgreSQL from terminal to create and setup a new db user

# connect to postgreSql command line tool
sudo -i -u postgres

# create a new user in db
createuser --interactive --pwprompt <username>

The cli tool will ask you to create a password for a new user.

But also you can setup a db user password manually:

ALTER USER <username> PASSWORD 'mynewpassword@#$@#sfsSDF';

3. pg_hba.conf

sudo find / -name pg_hba.conf

cat /opt/homebrew/var/postgresql@14/pg_hba.conf 

sudo cat /Library/PostgreSQL/18/data/pg_hba.conf 

#### postgresql remove macos

open /Library/PostgreSQL/<version>/uninstall-postgresql.app
open /Library/PostgreSQL/18/uninstall-postgresql.app

sudo /Library/PostgreSQL/<version>/uninstall-postgresql.app/Contents/MacOS/installbuilder.sh
sudo /Library/PostgreSQL/18/uninstall-postgresql.app/Contents/MacOS/installbuilder.sh