Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2013

    Unanswered: Create USER / DBMS Postgres 9.1

    Running on Postgres 9.1 Ubuntu 13.04.
    New to Postgres, not to DBMS.

    Also trying to see if there is a list of system defined privileges that I can refer to, such as in Oracle.

    I log in as Postgres user: psql -h localhost -U postgres
    and then I create a db and user and allow grants to the user like this:

    create user import_dbms_user with password 'import_dbms';
    create database import_dbms_db;
    grant all privileges on database import_dbms_db to import_dbms_user;

    \du shows:
    import_dbms_user | | {}
    postgres | Superuser, Create role, Create DB, Replication | {}

    In the pg_hba.conf I set as:
    local import_dbms_db import_dbms_user md5
    and restart Postgres.

    However when I try to run psql from the command line:
    psql -h localhost -U import_dbms_user -WI enter password when prompted
    Password for user import_dbms_user:
    psql: FATAL: database "import_dbms_user" does not exist

    But I get the error as above.

    Trying to understand what I may be doing wrong.

    Do I need to assign some kind of login role to import_dbms_user or such?

    i assumed in the pg_hba.conf the line above is all I needed to log in locally?
    local import_dbms_db import_dbms_user md5

    And instead of local I would enter IP address of machine from which I would want to log in to the server? import_dbms_db import_dbms_user md5

    I am running on a VM and am trying to run some python scripts with psycopg2 to load some data.

    So that script cannot log in either. Do I need to create any special role / privilege for that user to login from that script as well?

    Thank you for your help!


  2. #2
    Join Date
    Nov 2003
    Provided Answers: 23
    psql assumes you want to use a database with the same name as the user you use to log in.

    Compare this create statement:
    create database import_dbms_db;
    with this error message
    psql: FATAL: database "import_dbms_user" does not exist
    You need to tell psql which database you want to connect to:
    psql -h localhost -d import_dbms_db -U import_dbms_user
    or shorter:
    psql -h localhost import_dbms_db import_dbms_user
    More details are in the manual:
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags:

    Tips for good questions:

  3. #3
    Join Date
    Jun 2013
    Hi Shammat -

    Thanks. Worked great. I assumed it would assume the dbname to be import_dbms_db as import_dbms_user was granted admin privileges on it.

    Also I do have import_dbms_user and import_dbms_db in my pg_hba.conf as:
    local import_dbms_db import_dbms_user md5

    I still need that - correct? And I will need to have another entry specifying the ip addr of the machine to connect from if I am connecting from a different machine?

    So to connect from Python scripts (using psycopg2) do I need to specify the database to connect to as well?

    And if that python script is running from a different machine the ip addr of that machine needs to be in the pg_hba.conf?

    I ask as this is not connecting for me right now but I will check on the psycopg forum as well.

    Just wanted to confirm.

    Thank you for your help.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts