On Mac OS X, if you install the PostgreSQL database server, the tool for connecting to it via the terminal is installed, but it's not included in the paths the terminal looks for to run commands. You then have to type the full path to find the executable.
To do this, open a terminal console and type the following command:
export PATH="/System/Volumes/Data/Library/PostgreSQL/18/bin:$PATH"
Once that's done, the psql command can be run without any problems. The rest is standard usage.
What if the path is incorrect?
If another version of Postgres is installed, the version number should be replaced with the version actually installed (for example /System/Volumes/Data/Library/PostgreSQL/17/bin for version 17)
If the path is completely wrong, a search can be launched to find the correct path:
sur find / -name "postgresql"
And there you go, all you have to do is put the output path into the path, and it works.

