The right way to run psql is

sudo -u postgres psql

However, what is the right way to open the dir with postgresql files?

bom@ubuntu:/var/lib/postgresql/9.1$ cd main

-bash: cd: main: Permission denied

bom@ubuntu:/var/lib/postgresql/9.1$ sudo -u postgres cd main/

sudo: cd: command not found

So what the right way?

closed as unclear what you're asking by Falcon Momot, Ward, dawud, squillman, TheCleaner Aug 15 '13 at 17:49

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What are you trying to accomplish, broadly? This doesn't make any sense. – Falcon Momot Aug 15 '13 at 2:48
sudo -u postgres psql

is not the "right" way to do it; it is just one way to do it. Another way, which probably does what you want, is

sudo -iu postgres   # or sudo -su postgres
cd /var/lib/postgresql/9.1/main
psql ...

There's also

sudo -u postgres bash -c "cd /var/lib/postgresql/9.1/main && psql"

but I prefer the previous solution.

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