Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm trying to get psql to format nicely and am following the docs here. Right now, whenever I do a query on tables with lots of columns, no matter how big I make my screen each line overflows into the next line and producing a whole screen of unreadable junk.

The docs (link is above) say there's a way to align columns nicely for more readable output.

Normally, to start psql, I just type:

psql

and hit Enter. Now I'm trying:

psql \pset format aligned

And getting an error:

could not change directory to "/root"
psql: warning: extra command-line argument "aligned" ingored
psql: FATAL: Indent authentication failed for user "format"

Any ideas as to how I could get these command-line args to work for me?

share|improve this question
1  
On Ubuntu 13/10: sudo -u postgres psql . Then \c in the interactive shell results in "You are now connected to database "postgres" as user "postgres". – Timo Jul 9 '14 at 9:02
up vote 49 down vote accepted

These are not command line args. Run psql. Manage to log into database (so pass the hostname, port, user and database if needed). And then write it in the psql program.

Example (below are two commands, write the first one, press enter, wait for psql to login, write the second):

psql -h host -p 5900 -U username database
\pset format aligned
share|improve this answer
    
note the arrangement of keywords , try to write it in the same order and it works :) - Thanks dear – ImranNaqvi May 23 at 22:39
psql --pset=format=FORMAT

Great for executing queries from command line, e.g.

psql --pset=format=unaligned -c "select bandanavalue from bandana where bandanakey = 'atlassian.confluence.settings';"
share|improve this answer

Use \x Example from postgres manual:

    postgres=# \x
    postgres=# SELECT * FROM pg_stat_statements ORDER BY total_time DESC LIMIT 3;
    -[ RECORD 1 ]------------------------------------------------------------
    userid     | 10
    dbid       | 63781
    query      | UPDATE branches SET bbalance = bbalance + $1 WHERE bid = $2;
    calls      | 3000
    total_time | 20.716706
    rows       | 3000
    -[ RECORD 2 ]------------------------------------------------------------
    userid     | 10
    dbid       | 63781
    query      | UPDATE tellers SET tbalance = tbalance + $1 WHERE tid = $2;
    calls      | 3000
    total_time | 17.1107649999999
    rows       | 3000
    -[ RECORD 3 ]------------------------------------------------------------
    userid     | 10
    dbid       | 63781
    query      | UPDATE accounts SET abalance = abalance + $1 WHERE aid = $2;
    calls      | 3000
    total_time | 0.645601
    rows       | 3000
share|improve this answer

The steps to connect to the postgresql v9.3 server from windows-7 command line are as follows -

1. Go to the start --> All programs --> postgresql 9.3 --> Sql Shell (psql)
2. Just enter the details requested by postgres server, I've shown log snippet from my CMD.

(Note: "postgres" user will be the superuser for postgresql server, Pwd should be the one you entered during installation of postgresql)

Server [localhost]: localhost
Database [postgres]: postgres
Port [5432]: 5432
Username [postgres]: postgres
Password for user postgres:
psql (9.3.5)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

postgres=# CREATE ROLE prateek LOGIN PASSWORD 'test_123' NOINHERIT CREATEDB;
CREATE ROLE
postgres=#
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.