Reputation: 1764
I always have to give the command like sudo -u postgres psql
in order to login into Postgres console. What do I have to in order to login into postgres like sudo psql
or psql
The environment I am working on is Ubuntu Linux 12.04
Thanks in advance.
Upvotes: 0
Views: 291
Reputation: 61526
It's normal that after the installation, only the postgres
user is able to do anything with the database server. The installer can't assume that we'd want to open access to anyone else.
To give yourself access as a casual user, assuming as an example that your login name is joe
(your normal, non-priviledged user), you just need to create a corresponding user and database:
Inside psql as the postgres administrator (with sudo -u postgres psql
), issue:
CREATE USER joe;
CREATE DATABASE joe OWNER joe;
After that, when issuing psql
at the shell prompt, it will connect by default to your own database with your username. You no longer have to sudo to postgres
until you need to issue other administrator commands.
Upvotes: 1
Reputation: 3069
Would
psql -U psql
work for you?
EDIT:
I though you would mind about sudo
.
If your problem is rather typing -U <user>
, you could also set the environment variable PGUSER
. This could also be done in your shell's logon script, so that it will always be set.
The other enviroment variables of interest might be PGDATABASE
, PGHOST
, PGPORT
.
Upvotes: 0
Reputation: 95572
Your psql is in /usr/bin/psql. You shouldn't need to use sudo unless your permissions are wrong, or unless your link is wrong. (In later versions of PostgreSQL, /usr/bin/psql is a symbolic link to the executable. I don't know whether that's true in 8.4. On my home computer, it links to /usr/share/postgresql-common/pg_wrapper.)
The full skeleton syntax for psql is
psql -U username -h hostname -p portnumber database_name
So, for example, when I connect to my scratch database (named "sandbox"), I do it like this.
$ psql -U postgres -h localhost -p 5432 sandbox
You would substitute
Upvotes: 0