Search This Blog

29 November 2010

Important PSql commands

1. Command to connect to postgres
  • psql -h localhost -U postgres
2. Few general command that required when connected to Postges though shell
  • \h for help with SQL commands
  • \? for help on internal slash commands
  • \g or terminate with semicolon to execute query
  • \q to quit
3. Command to view the database assign to this user
  • \l to List databases
  • SELECT datname FROM pg_database;
4. Command to connect to a database
  • \c database-name  
5. Command to list tables in current database
  • \d to List tables in database
  • SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'
6. Command to describe a table structure
  • \d table-name

1 comment: