You are on page 1of 4

Jason Meridth's Blog (http://blog.jasonmeridth.

com/)
PostgreSQL Commond Line Cheat Sheet
Posted: Oct 02, 2012 | More posts about postgresql (../../categories/postgresql.html) command line (../../categories/command-line.html) | Source (index.md)
change to postgres user and open psql prompt
sudo -u postgres psql postgres
list databases
postgres=# \l
list roles
postgres=# \du
create role
postgres=#CREATE ROLE demorole1 WITH LOGIN ENCRYPTED PASSWORD 'password1' CREATEDB;
alter role
postgres=#ALTER ROLE demorole1 CREATEROLE CREATEDB REPLICATION SUPERUSER;
drop role
postgres=#DROP ROLE demorole1;
Share
Previous post (../testing-mail-from-the-command-line-on-ubuntu/) Next post (../bash-profile-vs-bashrc/)
create database
postgres=#CREATE DATABASE demodb1 WITH OWNER demorole1 ENCODING 'UTF8';
grant privileges to new user
GRANT ALL PRIVILEGES ON DATABASE demodb1 TO demorole1;
drop database
postgres=#DROP DATABASE demodb1;
connect to database
\c <databasename>
list tables in connected database
\dt
list columns on table
\d <tablename>
backup database
pg_dump <databasename> > <outfile>
9 Comments Jason Meridth Login
Sort by Best Share Favorite
Join the discussion
Reply
pebre79 6 months ago
Thanks! This was really useful, it got me out of a pickle. :)

1
Reply
chipcastle 10 days ago
Great stuff Jason!


Reply
lostcitizen a month ago
thanks!


Reply
Jimbo 2 months ago
Thank you very much!


Reply
John Scheianu 7 months ago
very practical, thanks!


Reply
dom 9 months ago
brief and up to the point. well done!


Reply
Sam 9 months ago
super useful.


Reply
Steven Chanin 10 months ago
Switching from MySQL to Postgres for new projects. This was helpful to quickly see the basic commands you use all the time!


Share
Share
Share
Share
Share
Share
Share
Share
Gitosis and Gitweb Part 1
2 comments 4 years ago
Jason Meridth Lasse: sorry for the delayed response. Usually
when you see a password request, and you're not wanting it, it
means that your local ssh key is not in the
Agile coaching
1 comment 4 years ago
Rachel Davies Nice summary! I particularly like "Agile Coach
== thick skin" which we don't explicitly say in the book but is
something we've both found to be true.
Gitosis and Gitweb Part 2
6 comments 4 years ago
Jason Meridth doh!!thank you Leandro. Can't believe I
missed that. I'll edit the post tonight (giving you credit)
Git reset, checkout & "bare double dash", and revert
1 comment 4 years ago
Bogdanfifa good job!:)
ALSO ON JASON MERIDTH
Reply
ash a year ago
awesome


WHAT'S THIS?
Subscribe Add Disqus to your site
Share
Contents 2014 Jason Meridth (mailto:jason@jasonmeridth.com) - Powered by Nikola (http://getnikola.com)
(http://creativecommons.org/licenses/by-nc-sa/2.5/ar/)

You might also like