How can I start PostgreSQL server on Mac OS X?

The Homebrew package manager includes launchctl plists to start automatically. For more information, run brew info postgres. Start manually pg_ctl -D /usr/local/var/postgres start Stop manually pg_ctl -D /usr/local/var/postgres stop Start automatically “To have launchd start postgresql now and restart at login:” brew services start postgresql What is the result of pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log … Read more

Select first row in each GROUP BY group?

DISTINCT ON is typically simplest and fastest for this in PostgreSQL. (For performance optimization for certain workloads see below.) SELECT DISTINCT ON (customer) id, customer, total FROM purchases ORDER BY customer, total DESC, id; Or shorter (if not as clear) with ordinal numbers of output columns: SELECT DISTINCT ON (2) id, customer, total FROM purchases … Read more

PostgreSQL: Show tables in PostgreSQL

From the psql command line interface, First, choose your database \c database_name Then, this shows all tables in the current schema: \dt Programmatically (or from the psql interface too, of course): SELECT * FROM pg_catalog.pg_tables; The system tables live in the pg_catalog database.