Home Explore Blog CI



postgresql

3rd chunk of `doc/src/sgml/start.sgml`
86bd0fe7128294b9a2a4918f675c0ff182421178e8acee5f0000000100000fa3
    If you see a message similar to:
<screen>
createdb: command not found
</screen>
    then <productname>PostgreSQL</productname> was not installed properly.  Either it was not
    installed at all or your shell's search path was not set to include it.
    Try calling the command with an absolute path instead:
<screen>
<prompt>$</prompt> <userinput>/usr/local/pgsql/bin/createdb mydb</userinput>
</screen>
    The path at your site might be different.  Contact your site
    administrator or check the installation instructions to
    correct the situation.
   </para>

   <para>
    Another response could be this:
<screen>
createdb: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
        Is the server running locally and accepting connections on that socket?
</screen>
    This means that the server was not started, or it is not listening
    where <command>createdb</command> expects to contact it.  Again, check the
    installation instructions or consult the administrator.
   </para>

   <para>
    Another response could be this:
<screen>
createdb: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL:  role "joe" does not exist
</screen>
    where your own login name is mentioned.  This will happen if the
    administrator has not created a <productname>PostgreSQL</productname> user account
    for you.  (<productname>PostgreSQL</productname> user accounts are distinct from
    operating system user accounts.)  If you are the administrator, see
    <xref linkend="user-manag"/> for help creating accounts.  You will need to
    become the operating system user under which <productname>PostgreSQL</productname>
    was installed (usually <literal>postgres</literal>) to create the first user
    account.  It could also be that you were assigned a
    <productname>PostgreSQL</productname> user name that is different from your
    operating system user name; in that case you need to use the <option>-U</option>
    switch or set the <envar>PGUSER</envar> environment variable to specify your
    <productname>PostgreSQL</productname> user name.
   </para>

   <para>
    If you have a user account but it does not have the privileges required to
    create a database, you will see the following:
<screen>
createdb: error: database creation failed: ERROR:  permission denied to create database
</screen>
    Not every user has authorization to create new databases.  If
    <productname>PostgreSQL</productname> refuses to create databases
    for you then the site administrator needs to grant you permission
    to create databases.  Consult your site administrator if this
    occurs.  If you installed <productname>PostgreSQL</productname>
    yourself then you should log in for the purposes of this tutorial
    under the user account that you started the server as.

    <footnote>
     <para>
      As an explanation for why this works:
      <productname>PostgreSQL</productname> user names are separate
      from operating system user accounts.  When you connect to a
      database, you can choose what
      <productname>PostgreSQL</productname> user name to connect as;
      if you don't, it will default to the same name as your current
      operating system account.  As it happens, there will always be a
      <productname>PostgreSQL</productname> user account that has the
      same name as the operating system user that started the server,
      and it also happens that that user always has permission to
      create databases.  Instead of logging in as that user you can
      also specify the <option>-U</option> option everywhere to select
      a <productname>PostgreSQL</productname> user name to connect as.
     </para>
    </footnote>
   </para>

   <para>
    You can also create databases with other names.
    <productname>PostgreSQL</productname> allows you to create any
    number of databases at a given site.  Database names must have an
    alphabetic first character and

Title: Troubleshooting Database Creation Errors in PostgreSQL
Summary
This section provides solutions to common errors encountered while creating a PostgreSQL database using the `createdb` command. It covers issues such as the command not being found (suggesting installation problems or an incorrect PATH), connection failures (indicating the server isn't running or is inaccessible), missing PostgreSQL user accounts, and permission denied errors. It advises users to check installation instructions, consult administrators, or use the correct PostgreSQL user credentials to resolve these problems.