Search This Blog

29 November 2010

Important Linux commands for PostgreSQL

  • createdb
    createdb tmpdb -h localhost -U postgres

    Create a new PostgreSQL database 
  • createuser
    createuser ekta –s -h localhost -U postgres –P

    Create a new PostgreSQL user. Above command will create a new user ekta with the permission of superuser (-s) . And –P will prompt you for the password for new user. If we write this command without –P, it will create used which will not require password authentication
  • dropdb
    dropdb tmpdb -h localhost -U postgres

    Remove an existing PostgreSQL database
  • dropuser
    dropuser ekta -h localhost -U postgres

    Drops (removes) a PostgreSQL user
  • pg_dump
    pg_dump -h localhost -U postgres tmpdb > tmpdb.sql
    pg_dump --insert -h localhost -U postgres tmpdb > tmpdb.sql

    All above command are used to take database dump. It will extract a PostgreSQL database into a script file. --insert option is used to dump data as insert command.
  • pg_dumpall
    pg_ dumpall -h localhost -U postgres > tmpdb.sql

    Extract all PostgreSQL databases into a script file
  • psql
    psql -h localhost -U postgres

    Open PostgreSQL interactive terminal
  • vacuumdb
    vacuumdb tmpdb -h localhost -U postgres

    Clean and analyze a PostgreSQL database
Note : For information on above command check Linux help using man command, for example man pg_dump

1 comment:

  1. cool, i'm currently using PostgreSQL with MVC2.0 .NET for my project latest project on linux OpenSUSE 11.3 ... project is under construstion, but you can see it at "www.DainikTender.com", currently we are hosting it on our windows 2008 server (For testing only)

    -- Amit Dave (AmitDave.RedTornado.in)

    ReplyDelete