Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010
    Location
    Orlando, FL
    Posts
    311
    Provided Answers: 1

    Unanswered: Create a Database Owner By User?

    I am trying to understand how I can create a new database in PostgreSQL and have it owned by a specific user and not the user I am connected to the database as.

    For example, I am logged into the 'postgres' database as the user 'postgres'. I want a new database called 'finance' and have it owned by a user that doesn't exist yet named 'maggie'. I searched the 'docs' and couldn't find any info that showed me how I could accomplish this task.

    When I tried the following, I get an error:

    Code:
    postgres=# CREATE DATABASE finance WITH OWNER = maggie;
    ERROR:  role "maggie" does not exist
    Not sure if it matters, but I am using psql (8.4.4).

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Just create the user before creating the database.
    Code:
    CREATE USER maggie WITH PASSWORD 'supersecret';
    CREATE DATABASE finance WITH OWNER = maggie;

Posting Permissions

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