Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
1  
What are you trying to accomplish, broadly? This doesn't make any sense. –  Falcon Momot Aug 15 '13 at 2:48
add comment

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 Answer

up vote 0 down vote accepted
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.

share|improve this answer
add comment

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