To get the psql, I simply installed the postgresapp for OSX which bundles the
psql . We can start the psql from its GUI, or added its bin to our
PATH. The specific path is:
You can also get psql by installing postgresql one click installer.
Connect to DB with psql
psql -h DbUrl -p DbPort -U DbUser
typically a password prompt comes up(if not add
-W to force it).
If we need to avoid entering pw interactively, we could set the pw as
PGPASSWORD in the PATH so that
psql could pickup.
For all other environment variables, reference here.
run batch sql file
-a -f YourScript.sql to the above command.
-a will print all nonempty input lines to standard output as they are read.
After the file is processed, psql terminates.
Or in the psql shell,
quit psql shell
select datname from pg_database;
select tablename from pg_table where tableowner='YOUROWNER';
select column_name, data_type, character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name = 'YourTableName';Or use
\d schemaName.tableName in psql shell.