psql: FATAL: role “postgres” does not exist











up vote
248
down vote

favorite
111












I'm a postgres novice.



I installed the postgres.app for mac. I was playing around with the psql commands and I accidentally dropped the postgres database. I don't know what was in it.



I'm currently working on a tutorial: http://www.rosslaird.com/blog/building-a-project-with-mezzanine/



And I'm stuck at sudo -u postgres psql postgres



ERROR MESSAGE: psql: FATAL: role "postgres" does not exist



$ which psql



/Applications/Postgres.app/Contents/MacOS/bin/psql


This is what prints out of psql -l



                                List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+---------+-------+---------------------------
user | user | UTF8 | en_US | en_US |
template0 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
template1 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
(3 rows)


So what are the steps I should take? Delete an everything related to psql and reinstall everything?



Thanks for the help guys!










share|improve this question




















  • 1




    Restarting Computer. Ensures Launchd from brew services start postresql is executed.
    – Michael Dimmitt
    Jun 26 '17 at 12:35















up vote
248
down vote

favorite
111












I'm a postgres novice.



I installed the postgres.app for mac. I was playing around with the psql commands and I accidentally dropped the postgres database. I don't know what was in it.



I'm currently working on a tutorial: http://www.rosslaird.com/blog/building-a-project-with-mezzanine/



And I'm stuck at sudo -u postgres psql postgres



ERROR MESSAGE: psql: FATAL: role "postgres" does not exist



$ which psql



/Applications/Postgres.app/Contents/MacOS/bin/psql


This is what prints out of psql -l



                                List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+---------+-------+---------------------------
user | user | UTF8 | en_US | en_US |
template0 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
template1 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
(3 rows)


So what are the steps I should take? Delete an everything related to psql and reinstall everything?



Thanks for the help guys!










share|improve this question




















  • 1




    Restarting Computer. Ensures Launchd from brew services start postresql is executed.
    – Michael Dimmitt
    Jun 26 '17 at 12:35













up vote
248
down vote

favorite
111









up vote
248
down vote

favorite
111






111





I'm a postgres novice.



I installed the postgres.app for mac. I was playing around with the psql commands and I accidentally dropped the postgres database. I don't know what was in it.



I'm currently working on a tutorial: http://www.rosslaird.com/blog/building-a-project-with-mezzanine/



And I'm stuck at sudo -u postgres psql postgres



ERROR MESSAGE: psql: FATAL: role "postgres" does not exist



$ which psql



/Applications/Postgres.app/Contents/MacOS/bin/psql


This is what prints out of psql -l



                                List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+---------+-------+---------------------------
user | user | UTF8 | en_US | en_US |
template0 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
template1 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
(3 rows)


So what are the steps I should take? Delete an everything related to psql and reinstall everything?



Thanks for the help guys!










share|improve this question















I'm a postgres novice.



I installed the postgres.app for mac. I was playing around with the psql commands and I accidentally dropped the postgres database. I don't know what was in it.



I'm currently working on a tutorial: http://www.rosslaird.com/blog/building-a-project-with-mezzanine/



And I'm stuck at sudo -u postgres psql postgres



ERROR MESSAGE: psql: FATAL: role "postgres" does not exist



$ which psql



/Applications/Postgres.app/Contents/MacOS/bin/psql


This is what prints out of psql -l



                                List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+---------+-------+---------------------------
user | user | UTF8 | en_US | en_US |
template0 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
template1 | user | UTF8 | en_US | en_US | =c/user +
| | | | | user =CTc/user
(3 rows)


So what are the steps I should take? Delete an everything related to psql and reinstall everything?



Thanks for the help guys!







macos postgresql terminal






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 18 '15 at 5:01









Daniil Ryzhkov

5,39312549




5,39312549










asked Mar 8 '13 at 19:31









user805981

2,13242349




2,13242349








  • 1




    Restarting Computer. Ensures Launchd from brew services start postresql is executed.
    – Michael Dimmitt
    Jun 26 '17 at 12:35














  • 1




    Restarting Computer. Ensures Launchd from brew services start postresql is executed.
    – Michael Dimmitt
    Jun 26 '17 at 12:35








1




1




Restarting Computer. Ensures Launchd from brew services start postresql is executed.
– Michael Dimmitt
Jun 26 '17 at 12:35




Restarting Computer. Ensures Launchd from brew services start postresql is executed.
– Michael Dimmitt
Jun 26 '17 at 12:35












15 Answers
15






active

oldest

votes

















up vote
258
down vote



accepted










Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.



But the first step is to check the missing role: What is the output within psql of the command du ? On my Ubuntu system the relevant line looks like this:



                              List of roles
Role name | Attributes | Member of
-----------+-----------------------------------+-----------
postgres | Superuser, Create role, Create DB | {}


If there is not at least one role with superuser, then you have a problem :-)



If there is one, you can use that to login. And looking at the output of your l command: The permissions for user on the template0 and template1 databases are the same as on my Ubuntu system for the superuser postgres. So I think your setup simple uses user as the superuser. So you could try this command to login:



sudo -u user psql user


If user is really the DB superuser you can create another DB superuser and a private, empty database for him:



CREATE USER postgres SUPERUSER;
CREATE DATABASE postgres WITH OWNER postgres;


But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.






share|improve this answer

















  • 7




    For me, the user was not being created - this worked instead CREATE USER postgres WITH SUPERUSER PASSWORD 'password'; am using postgres v10.
    – arcseldon
    Nov 4 '17 at 1:10






  • 8




    If you installed Postgres from homebrew then you need to run /usr/local/opt/postgres/bin/createuser -s postgres in your terminal
    – user3402754
    Sep 5 at 18:36




















up vote
215
down vote













The key is "I installed the postgres.app for mac." This application sets up the local PostgreSQL installation with a database superuser whose role name is the same as your login (short) name.




When Postgres.app first starts up, it creates the $USER database,
which is the default database for psql when none is specified. The
default user is $USER, with no password.




Some scripts (e.g., a database backup created with pgdump on a Linux systsem) and tutorials will assume the superuser has the traditional role name of postgres.



You can make your local install look a bit more traditional and avoid these problems by doing a one time:



/Applications/Postgres.app/Contents/Versions/9.*/bin/createuser -s postgres


which will make those FATAL: role "postgres" does not exist go away.






share|improve this answer



















  • 7




    That createuser command worked for me. Thanks!
    – knownasilya
    Aug 21 '13 at 14:32






  • 89




    If you're using postgres from Homebrew, then you want /usr/local/Cellar/postgresql/9.2.4/bin/createuser -s postgres (for version 9.2.4, obviously).
    – Roger Lipscombe
    Mar 13 '14 at 14:21






  • 1




    For postgres.app 9.3, they seem to have re-arranged the directories. I tried: /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres, but this generated the same eror message: "createuser: could not connect to database postgres: FATAL: role "postgres" does not exist"
    – Michael Coxon
    Sep 25 '14 at 23:22






  • 7




    /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres ran correctly for me.
    – cjspurgeon
    Nov 13 '14 at 22:31






  • 5




    @RogerLipscombe if you run brew link postgresql after the installation, there's no need to append the whole path to createuser, a simple createuser -s postgres will work great
    – AlessioX
    Sep 7 '16 at 14:39


















up vote
155
down vote













For MAC:




  1. Install Homebrew

  2. brew install postgres

  3. initdb /usr/local/var/postgres


  4. /usr/local/Cellar/postgresql/<version>/bin/createuser -s postgres or /usr/local/opt/postgres/bin/createuser -s postgres which will just use the latest version.

  5. start postgres server manually: pg_ctl -D /usr/local/var/postgres start




To start server at startup




  • mkdir -p ~/Library/LaunchAgents

  • ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

  • launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist




Now, it is set up, login using psql -U postgres -h localhost or use PgAdmin for GUI.



By default user postgres will not have any login password.



Check this site for more articles like this: https://medium.com/@Nithanaroy/installing-postgres-on-mac-18f017c5d3f7






share|improve this answer



















  • 1




    Thats a great point. Thanks for the inputs.
    – Nitin
    Feb 10 '16 at 22:28






  • 3




    With the newest brew install you can do brew services start postgresql to start postgres
    – Automatico
    Jan 20 '17 at 12:40










  • not every hero wears a cape. love you man <3
    – Pranjal
    Aug 3 '17 at 14:32










  • This solution worked for me. Big thanks.
    – VikC
    Oct 4 '17 at 12:36


















up vote
17
down vote













createuser postgres --interactive


or make a superuser postgresl just with



createuser postgres -s





share|improve this answer





















  • Cool stackoverflow.com/questions/17633422/…
    – unom
    Oct 26 '17 at 10:02


















up vote
15
down vote













For me, this code worked:



/Applications/Postgres.app/Contents/Versions/9.4/bin/createuser -s postgres


it came from here:
http://talk.growstuff.org/t/fatal-role-postgres-does-not-exist/216/4






share|improve this answer





















  • Works for me too! You saved my bacon.
    – Dave Munger
    Jan 6 '16 at 22:22






  • 1




    I get role "me" does not exist
    – SuperUberDuper
    Feb 29 '16 at 22:52


















up vote
10
down vote













First you need create a user:



sudo -u postgres createuser --superuser $USER


After you create a database:



sudo -u postgres createdb $USER


Change $USER to your system username.



You can see the the complete solution here.






share|improve this answer






























    up vote
    8
    down vote













    I needed to unset $PGUSER:



    $ unset PGUSER
    $ createuser -s postgres





    share|improve this answer




























      up vote
      7
      down vote













      Running this on the command line should fix it



      /Applications/Postgres.app/Contents/Versions/9.4/bin/createdb <Mac OSX Username Here>






      share|improve this answer





















      • requires: postgresapp.com
        – tandy
        May 25 '15 at 18:59






      • 1




        This is the only thing that worked for me. Thank you!
        – Herb Meehan
        Aug 24 '15 at 16:01


















      up vote
      4
      down vote













      Dropping the postgres database doesn't really matter. This database is initially empty and its purpose is simply for the postgres user to have a kind of "home" to connect to, should it need one.



      Still you may recreate it with the SQL command CREATE DATABASE postgres;



      Note that the tutorial mentioned in the question is not written with postgres.app in mind.
      Contrary to PostgreSQL for Unix in general, postgres.app tries to look like a normal application as opposed to a service that would be run by a dedicated postgres user having different privileges than your normal user. postgres.app is run and managed by your own account.



      So instead of this command: sudo -u postgres psql -U postgres, it would be more in the spirit of postgres.app to just issue: psql, which automatically connects to a database matching your users's name, and with a db account of the same name that happens to be superuser, so it can do anything permissions-wise.






      share|improve this answer





















      • Okay. But why do I get an error ERROR: cannot drop the currently open database when I try to delete the user db? So is it not a good practice to use this postgres.app?
        – user805981
        Mar 8 '13 at 21:10










      • You cannot drop a db while connected to it. why would you want to delete it, anyway? It's here for your convenience.
        – Daniel Vérité
        Mar 8 '13 at 21:15










      • I just wanted to see if I could. So it's like a default database correct when I boot up my psql and postgres.app? Now what about the access privileges? I am not able to set them anymore? I see that template0 and template1 has access privileges
        – user805981
        Mar 8 '13 at 21:29












      • @user805981 Postgres.app is for testing and development purposes; it's a PostgreSQL package from Heroku that's designed to make it easier for Mac users developing with Ruby on Rails to test with PostgreSQL instead of the default SQLite. Rails uses tended to test with SQLite and deploy to PostgreSQL which caused all sorts of problems, so Heroku tried to make it easier to test on PostgreSQL too. Postgres.app is fine for testing, but I wouldn't consider using it for production or real data, that's just not what it's for.
        – Craig Ringer
        Mar 9 '13 at 0:32


















      up vote
      3
      down vote













      For what it is worth, i have ubuntu and many packages installed and it went in conflict with it.



      For me the right answer was:



      sudo -i -u postgres-xc
      psql





      share|improve this answer




























        up vote
        1
        down vote













        This is the only one that fixed it for me :



        createuser -s -U $USER





        share|improve this answer

















        • 1




          This makes the current user a system superuser rather than just a postgres superuser. I would say this would be generally a bad idea as it circumvents the usual security policies. You should user sudo to gain temporary superuser privileges.
          – Sean Dawson
          Mar 29 '16 at 21:54


















        up vote
        1
        down vote













        On Ubuntu system, I purged the PostgreSQL and re-installed it. All the databases are restored.
        This solved the problem for me.



        Advice - Take the backup of the databases to be on the safer side.






        share|improve this answer








        New contributor




        Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.

























          up vote
          0
          down vote













          I don't think that sudo is needed here because psql -l returns a list of databases. This tells me that initdb was run under the user's current user, not under the postgres user.



          You can just:



          psql


          And continue the tutorial.



          I would suggest A.H's general points of creating the postgres user and db because many applications may expect this to exist.



          A brief explanation:



          PostgreSQL will not run with administrative access to the operating system. Instead it runs with an ordinary user, and in order to support peer authentication (asking the OS who is trying to connect) it creates a user and db with the user that runs the initialization process. In this case it was your normal user.






          share|improve this answer





















          • clears few important distinction in postgres. Thank you.
            – imsrgadich
            Mar 27 at 14:05


















          up vote
          0
          down vote













          I became stuck on this issue having executed brew services stop postgresql the day prior.
          The day following: brew services start postgresql would not work. This is because as is shown when you install using homebrew. postgresql uses a launchd ... which loads when your computer is powered on.

          resolution:
          brew services start postgresql
          Restart your computer.






          share|improve this answer




























            up vote
            0
            down vote













            The du command return:




            Role name = postgres@implicit_files




            And that command postgres=# password postgres return error:




            ERROR: role "postgres" does not exist.




            But that postgres=# password postgres@implicit_files run fine.



            Also after sudo -u postgres createuser -s postgres the first variant also work.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15301826%2fpsql-fatal-role-postgres-does-not-exist%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              15 Answers
              15






              active

              oldest

              votes








              15 Answers
              15






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              258
              down vote



              accepted










              Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.



              But the first step is to check the missing role: What is the output within psql of the command du ? On my Ubuntu system the relevant line looks like this:



                                            List of roles
              Role name | Attributes | Member of
              -----------+-----------------------------------+-----------
              postgres | Superuser, Create role, Create DB | {}


              If there is not at least one role with superuser, then you have a problem :-)



              If there is one, you can use that to login. And looking at the output of your l command: The permissions for user on the template0 and template1 databases are the same as on my Ubuntu system for the superuser postgres. So I think your setup simple uses user as the superuser. So you could try this command to login:



              sudo -u user psql user


              If user is really the DB superuser you can create another DB superuser and a private, empty database for him:



              CREATE USER postgres SUPERUSER;
              CREATE DATABASE postgres WITH OWNER postgres;


              But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.






              share|improve this answer

















              • 7




                For me, the user was not being created - this worked instead CREATE USER postgres WITH SUPERUSER PASSWORD 'password'; am using postgres v10.
                – arcseldon
                Nov 4 '17 at 1:10






              • 8




                If you installed Postgres from homebrew then you need to run /usr/local/opt/postgres/bin/createuser -s postgres in your terminal
                – user3402754
                Sep 5 at 18:36

















              up vote
              258
              down vote



              accepted










              Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.



              But the first step is to check the missing role: What is the output within psql of the command du ? On my Ubuntu system the relevant line looks like this:



                                            List of roles
              Role name | Attributes | Member of
              -----------+-----------------------------------+-----------
              postgres | Superuser, Create role, Create DB | {}


              If there is not at least one role with superuser, then you have a problem :-)



              If there is one, you can use that to login. And looking at the output of your l command: The permissions for user on the template0 and template1 databases are the same as on my Ubuntu system for the superuser postgres. So I think your setup simple uses user as the superuser. So you could try this command to login:



              sudo -u user psql user


              If user is really the DB superuser you can create another DB superuser and a private, empty database for him:



              CREATE USER postgres SUPERUSER;
              CREATE DATABASE postgres WITH OWNER postgres;


              But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.






              share|improve this answer

















              • 7




                For me, the user was not being created - this worked instead CREATE USER postgres WITH SUPERUSER PASSWORD 'password'; am using postgres v10.
                – arcseldon
                Nov 4 '17 at 1:10






              • 8




                If you installed Postgres from homebrew then you need to run /usr/local/opt/postgres/bin/createuser -s postgres in your terminal
                – user3402754
                Sep 5 at 18:36















              up vote
              258
              down vote



              accepted







              up vote
              258
              down vote



              accepted






              Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.



              But the first step is to check the missing role: What is the output within psql of the command du ? On my Ubuntu system the relevant line looks like this:



                                            List of roles
              Role name | Attributes | Member of
              -----------+-----------------------------------+-----------
              postgres | Superuser, Create role, Create DB | {}


              If there is not at least one role with superuser, then you have a problem :-)



              If there is one, you can use that to login. And looking at the output of your l command: The permissions for user on the template0 and template1 databases are the same as on my Ubuntu system for the superuser postgres. So I think your setup simple uses user as the superuser. So you could try this command to login:



              sudo -u user psql user


              If user is really the DB superuser you can create another DB superuser and a private, empty database for him:



              CREATE USER postgres SUPERUSER;
              CREATE DATABASE postgres WITH OWNER postgres;


              But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.






              share|improve this answer












              Note that the error message does NOT talk about a missing database, it talks about a missing role. Later in the login process it might also stumble over the missing database.



              But the first step is to check the missing role: What is the output within psql of the command du ? On my Ubuntu system the relevant line looks like this:



                                            List of roles
              Role name | Attributes | Member of
              -----------+-----------------------------------+-----------
              postgres | Superuser, Create role, Create DB | {}


              If there is not at least one role with superuser, then you have a problem :-)



              If there is one, you can use that to login. And looking at the output of your l command: The permissions for user on the template0 and template1 databases are the same as on my Ubuntu system for the superuser postgres. So I think your setup simple uses user as the superuser. So you could try this command to login:



              sudo -u user psql user


              If user is really the DB superuser you can create another DB superuser and a private, empty database for him:



              CREATE USER postgres SUPERUSER;
              CREATE DATABASE postgres WITH OWNER postgres;


              But since your postgres.app setup does not seem to do this, you also should not. Simple adapt the tutorial.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Mar 9 '13 at 10:13









              A.H.

              44.5k116895




              44.5k116895








              • 7




                For me, the user was not being created - this worked instead CREATE USER postgres WITH SUPERUSER PASSWORD 'password'; am using postgres v10.
                – arcseldon
                Nov 4 '17 at 1:10






              • 8




                If you installed Postgres from homebrew then you need to run /usr/local/opt/postgres/bin/createuser -s postgres in your terminal
                – user3402754
                Sep 5 at 18:36
















              • 7




                For me, the user was not being created - this worked instead CREATE USER postgres WITH SUPERUSER PASSWORD 'password'; am using postgres v10.
                – arcseldon
                Nov 4 '17 at 1:10






              • 8




                If you installed Postgres from homebrew then you need to run /usr/local/opt/postgres/bin/createuser -s postgres in your terminal
                – user3402754
                Sep 5 at 18:36










              7




              7




              For me, the user was not being created - this worked instead CREATE USER postgres WITH SUPERUSER PASSWORD 'password'; am using postgres v10.
              – arcseldon
              Nov 4 '17 at 1:10




              For me, the user was not being created - this worked instead CREATE USER postgres WITH SUPERUSER PASSWORD 'password'; am using postgres v10.
              – arcseldon
              Nov 4 '17 at 1:10




              8




              8




              If you installed Postgres from homebrew then you need to run /usr/local/opt/postgres/bin/createuser -s postgres in your terminal
              – user3402754
              Sep 5 at 18:36






              If you installed Postgres from homebrew then you need to run /usr/local/opt/postgres/bin/createuser -s postgres in your terminal
              – user3402754
              Sep 5 at 18:36














              up vote
              215
              down vote













              The key is "I installed the postgres.app for mac." This application sets up the local PostgreSQL installation with a database superuser whose role name is the same as your login (short) name.




              When Postgres.app first starts up, it creates the $USER database,
              which is the default database for psql when none is specified. The
              default user is $USER, with no password.




              Some scripts (e.g., a database backup created with pgdump on a Linux systsem) and tutorials will assume the superuser has the traditional role name of postgres.



              You can make your local install look a bit more traditional and avoid these problems by doing a one time:



              /Applications/Postgres.app/Contents/Versions/9.*/bin/createuser -s postgres


              which will make those FATAL: role "postgres" does not exist go away.






              share|improve this answer



















              • 7




                That createuser command worked for me. Thanks!
                – knownasilya
                Aug 21 '13 at 14:32






              • 89




                If you're using postgres from Homebrew, then you want /usr/local/Cellar/postgresql/9.2.4/bin/createuser -s postgres (for version 9.2.4, obviously).
                – Roger Lipscombe
                Mar 13 '14 at 14:21






              • 1




                For postgres.app 9.3, they seem to have re-arranged the directories. I tried: /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres, but this generated the same eror message: "createuser: could not connect to database postgres: FATAL: role "postgres" does not exist"
                – Michael Coxon
                Sep 25 '14 at 23:22






              • 7




                /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres ran correctly for me.
                – cjspurgeon
                Nov 13 '14 at 22:31






              • 5




                @RogerLipscombe if you run brew link postgresql after the installation, there's no need to append the whole path to createuser, a simple createuser -s postgres will work great
                – AlessioX
                Sep 7 '16 at 14:39















              up vote
              215
              down vote













              The key is "I installed the postgres.app for mac." This application sets up the local PostgreSQL installation with a database superuser whose role name is the same as your login (short) name.




              When Postgres.app first starts up, it creates the $USER database,
              which is the default database for psql when none is specified. The
              default user is $USER, with no password.




              Some scripts (e.g., a database backup created with pgdump on a Linux systsem) and tutorials will assume the superuser has the traditional role name of postgres.



              You can make your local install look a bit more traditional and avoid these problems by doing a one time:



              /Applications/Postgres.app/Contents/Versions/9.*/bin/createuser -s postgres


              which will make those FATAL: role "postgres" does not exist go away.






              share|improve this answer



















              • 7




                That createuser command worked for me. Thanks!
                – knownasilya
                Aug 21 '13 at 14:32






              • 89




                If you're using postgres from Homebrew, then you want /usr/local/Cellar/postgresql/9.2.4/bin/createuser -s postgres (for version 9.2.4, obviously).
                – Roger Lipscombe
                Mar 13 '14 at 14:21






              • 1




                For postgres.app 9.3, they seem to have re-arranged the directories. I tried: /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres, but this generated the same eror message: "createuser: could not connect to database postgres: FATAL: role "postgres" does not exist"
                – Michael Coxon
                Sep 25 '14 at 23:22






              • 7




                /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres ran correctly for me.
                – cjspurgeon
                Nov 13 '14 at 22:31






              • 5




                @RogerLipscombe if you run brew link postgresql after the installation, there's no need to append the whole path to createuser, a simple createuser -s postgres will work great
                – AlessioX
                Sep 7 '16 at 14:39













              up vote
              215
              down vote










              up vote
              215
              down vote









              The key is "I installed the postgres.app for mac." This application sets up the local PostgreSQL installation with a database superuser whose role name is the same as your login (short) name.




              When Postgres.app first starts up, it creates the $USER database,
              which is the default database for psql when none is specified. The
              default user is $USER, with no password.




              Some scripts (e.g., a database backup created with pgdump on a Linux systsem) and tutorials will assume the superuser has the traditional role name of postgres.



              You can make your local install look a bit more traditional and avoid these problems by doing a one time:



              /Applications/Postgres.app/Contents/Versions/9.*/bin/createuser -s postgres


              which will make those FATAL: role "postgres" does not exist go away.






              share|improve this answer














              The key is "I installed the postgres.app for mac." This application sets up the local PostgreSQL installation with a database superuser whose role name is the same as your login (short) name.




              When Postgres.app first starts up, it creates the $USER database,
              which is the default database for psql when none is specified. The
              default user is $USER, with no password.




              Some scripts (e.g., a database backup created with pgdump on a Linux systsem) and tutorials will assume the superuser has the traditional role name of postgres.



              You can make your local install look a bit more traditional and avoid these problems by doing a one time:



              /Applications/Postgres.app/Contents/Versions/9.*/bin/createuser -s postgres


              which will make those FATAL: role "postgres" does not exist go away.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Oct 23 at 21:08









              Laurel

              4,70092136




              4,70092136










              answered Jul 23 '13 at 14:25









              jwd630

              3,18411322




              3,18411322








              • 7




                That createuser command worked for me. Thanks!
                – knownasilya
                Aug 21 '13 at 14:32






              • 89




                If you're using postgres from Homebrew, then you want /usr/local/Cellar/postgresql/9.2.4/bin/createuser -s postgres (for version 9.2.4, obviously).
                – Roger Lipscombe
                Mar 13 '14 at 14:21






              • 1




                For postgres.app 9.3, they seem to have re-arranged the directories. I tried: /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres, but this generated the same eror message: "createuser: could not connect to database postgres: FATAL: role "postgres" does not exist"
                – Michael Coxon
                Sep 25 '14 at 23:22






              • 7




                /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres ran correctly for me.
                – cjspurgeon
                Nov 13 '14 at 22:31






              • 5




                @RogerLipscombe if you run brew link postgresql after the installation, there's no need to append the whole path to createuser, a simple createuser -s postgres will work great
                – AlessioX
                Sep 7 '16 at 14:39














              • 7




                That createuser command worked for me. Thanks!
                – knownasilya
                Aug 21 '13 at 14:32






              • 89




                If you're using postgres from Homebrew, then you want /usr/local/Cellar/postgresql/9.2.4/bin/createuser -s postgres (for version 9.2.4, obviously).
                – Roger Lipscombe
                Mar 13 '14 at 14:21






              • 1




                For postgres.app 9.3, they seem to have re-arranged the directories. I tried: /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres, but this generated the same eror message: "createuser: could not connect to database postgres: FATAL: role "postgres" does not exist"
                – Michael Coxon
                Sep 25 '14 at 23:22






              • 7




                /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres ran correctly for me.
                – cjspurgeon
                Nov 13 '14 at 22:31






              • 5




                @RogerLipscombe if you run brew link postgresql after the installation, there's no need to append the whole path to createuser, a simple createuser -s postgres will work great
                – AlessioX
                Sep 7 '16 at 14:39








              7




              7




              That createuser command worked for me. Thanks!
              – knownasilya
              Aug 21 '13 at 14:32




              That createuser command worked for me. Thanks!
              – knownasilya
              Aug 21 '13 at 14:32




              89




              89




              If you're using postgres from Homebrew, then you want /usr/local/Cellar/postgresql/9.2.4/bin/createuser -s postgres (for version 9.2.4, obviously).
              – Roger Lipscombe
              Mar 13 '14 at 14:21




              If you're using postgres from Homebrew, then you want /usr/local/Cellar/postgresql/9.2.4/bin/createuser -s postgres (for version 9.2.4, obviously).
              – Roger Lipscombe
              Mar 13 '14 at 14:21




              1




              1




              For postgres.app 9.3, they seem to have re-arranged the directories. I tried: /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres, but this generated the same eror message: "createuser: could not connect to database postgres: FATAL: role "postgres" does not exist"
              – Michael Coxon
              Sep 25 '14 at 23:22




              For postgres.app 9.3, they seem to have re-arranged the directories. I tried: /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres, but this generated the same eror message: "createuser: could not connect to database postgres: FATAL: role "postgres" does not exist"
              – Michael Coxon
              Sep 25 '14 at 23:22




              7




              7




              /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres ran correctly for me.
              – cjspurgeon
              Nov 13 '14 at 22:31




              /Applications/Postgres.app/Contents/Versions/9.3/bin/createuser -s postgres ran correctly for me.
              – cjspurgeon
              Nov 13 '14 at 22:31




              5




              5




              @RogerLipscombe if you run brew link postgresql after the installation, there's no need to append the whole path to createuser, a simple createuser -s postgres will work great
              – AlessioX
              Sep 7 '16 at 14:39




              @RogerLipscombe if you run brew link postgresql after the installation, there's no need to append the whole path to createuser, a simple createuser -s postgres will work great
              – AlessioX
              Sep 7 '16 at 14:39










              up vote
              155
              down vote













              For MAC:




              1. Install Homebrew

              2. brew install postgres

              3. initdb /usr/local/var/postgres


              4. /usr/local/Cellar/postgresql/<version>/bin/createuser -s postgres or /usr/local/opt/postgres/bin/createuser -s postgres which will just use the latest version.

              5. start postgres server manually: pg_ctl -D /usr/local/var/postgres start




              To start server at startup




              • mkdir -p ~/Library/LaunchAgents

              • ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

              • launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist




              Now, it is set up, login using psql -U postgres -h localhost or use PgAdmin for GUI.



              By default user postgres will not have any login password.



              Check this site for more articles like this: https://medium.com/@Nithanaroy/installing-postgres-on-mac-18f017c5d3f7






              share|improve this answer



















              • 1




                Thats a great point. Thanks for the inputs.
                – Nitin
                Feb 10 '16 at 22:28






              • 3




                With the newest brew install you can do brew services start postgresql to start postgres
                – Automatico
                Jan 20 '17 at 12:40










              • not every hero wears a cape. love you man <3
                – Pranjal
                Aug 3 '17 at 14:32










              • This solution worked for me. Big thanks.
                – VikC
                Oct 4 '17 at 12:36















              up vote
              155
              down vote













              For MAC:




              1. Install Homebrew

              2. brew install postgres

              3. initdb /usr/local/var/postgres


              4. /usr/local/Cellar/postgresql/<version>/bin/createuser -s postgres or /usr/local/opt/postgres/bin/createuser -s postgres which will just use the latest version.

              5. start postgres server manually: pg_ctl -D /usr/local/var/postgres start




              To start server at startup




              • mkdir -p ~/Library/LaunchAgents

              • ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

              • launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist




              Now, it is set up, login using psql -U postgres -h localhost or use PgAdmin for GUI.



              By default user postgres will not have any login password.



              Check this site for more articles like this: https://medium.com/@Nithanaroy/installing-postgres-on-mac-18f017c5d3f7






              share|improve this answer



















              • 1




                Thats a great point. Thanks for the inputs.
                – Nitin
                Feb 10 '16 at 22:28






              • 3




                With the newest brew install you can do brew services start postgresql to start postgres
                – Automatico
                Jan 20 '17 at 12:40










              • not every hero wears a cape. love you man <3
                – Pranjal
                Aug 3 '17 at 14:32










              • This solution worked for me. Big thanks.
                – VikC
                Oct 4 '17 at 12:36













              up vote
              155
              down vote










              up vote
              155
              down vote









              For MAC:




              1. Install Homebrew

              2. brew install postgres

              3. initdb /usr/local/var/postgres


              4. /usr/local/Cellar/postgresql/<version>/bin/createuser -s postgres or /usr/local/opt/postgres/bin/createuser -s postgres which will just use the latest version.

              5. start postgres server manually: pg_ctl -D /usr/local/var/postgres start




              To start server at startup




              • mkdir -p ~/Library/LaunchAgents

              • ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

              • launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist




              Now, it is set up, login using psql -U postgres -h localhost or use PgAdmin for GUI.



              By default user postgres will not have any login password.



              Check this site for more articles like this: https://medium.com/@Nithanaroy/installing-postgres-on-mac-18f017c5d3f7






              share|improve this answer














              For MAC:




              1. Install Homebrew

              2. brew install postgres

              3. initdb /usr/local/var/postgres


              4. /usr/local/Cellar/postgresql/<version>/bin/createuser -s postgres or /usr/local/opt/postgres/bin/createuser -s postgres which will just use the latest version.

              5. start postgres server manually: pg_ctl -D /usr/local/var/postgres start




              To start server at startup




              • mkdir -p ~/Library/LaunchAgents

              • ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

              • launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist




              Now, it is set up, login using psql -U postgres -h localhost or use PgAdmin for GUI.



              By default user postgres will not have any login password.



              Check this site for more articles like this: https://medium.com/@Nithanaroy/installing-postgres-on-mac-18f017c5d3f7







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 18 at 20:20

























              answered Feb 10 '16 at 6:19









              Nitin

              2,57911419




              2,57911419








              • 1




                Thats a great point. Thanks for the inputs.
                – Nitin
                Feb 10 '16 at 22:28






              • 3




                With the newest brew install you can do brew services start postgresql to start postgres
                – Automatico
                Jan 20 '17 at 12:40










              • not every hero wears a cape. love you man <3
                – Pranjal
                Aug 3 '17 at 14:32










              • This solution worked for me. Big thanks.
                – VikC
                Oct 4 '17 at 12:36














              • 1




                Thats a great point. Thanks for the inputs.
                – Nitin
                Feb 10 '16 at 22:28






              • 3




                With the newest brew install you can do brew services start postgresql to start postgres
                – Automatico
                Jan 20 '17 at 12:40










              • not every hero wears a cape. love you man <3
                – Pranjal
                Aug 3 '17 at 14:32










              • This solution worked for me. Big thanks.
                – VikC
                Oct 4 '17 at 12:36








              1




              1




              Thats a great point. Thanks for the inputs.
              – Nitin
              Feb 10 '16 at 22:28




              Thats a great point. Thanks for the inputs.
              – Nitin
              Feb 10 '16 at 22:28




              3




              3




              With the newest brew install you can do brew services start postgresql to start postgres
              – Automatico
              Jan 20 '17 at 12:40




              With the newest brew install you can do brew services start postgresql to start postgres
              – Automatico
              Jan 20 '17 at 12:40












              not every hero wears a cape. love you man <3
              – Pranjal
              Aug 3 '17 at 14:32




              not every hero wears a cape. love you man <3
              – Pranjal
              Aug 3 '17 at 14:32












              This solution worked for me. Big thanks.
              – VikC
              Oct 4 '17 at 12:36




              This solution worked for me. Big thanks.
              – VikC
              Oct 4 '17 at 12:36










              up vote
              17
              down vote













              createuser postgres --interactive


              or make a superuser postgresl just with



              createuser postgres -s





              share|improve this answer





















              • Cool stackoverflow.com/questions/17633422/…
                – unom
                Oct 26 '17 at 10:02















              up vote
              17
              down vote













              createuser postgres --interactive


              or make a superuser postgresl just with



              createuser postgres -s





              share|improve this answer





















              • Cool stackoverflow.com/questions/17633422/…
                – unom
                Oct 26 '17 at 10:02













              up vote
              17
              down vote










              up vote
              17
              down vote









              createuser postgres --interactive


              or make a superuser postgresl just with



              createuser postgres -s





              share|improve this answer












              createuser postgres --interactive


              or make a superuser postgresl just with



              createuser postgres -s






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Aug 10 '17 at 20:10









              SyntheticMeshwork

              755612




              755612












              • Cool stackoverflow.com/questions/17633422/…
                – unom
                Oct 26 '17 at 10:02


















              • Cool stackoverflow.com/questions/17633422/…
                – unom
                Oct 26 '17 at 10:02
















              Cool stackoverflow.com/questions/17633422/…
              – unom
              Oct 26 '17 at 10:02




              Cool stackoverflow.com/questions/17633422/…
              – unom
              Oct 26 '17 at 10:02










              up vote
              15
              down vote













              For me, this code worked:



              /Applications/Postgres.app/Contents/Versions/9.4/bin/createuser -s postgres


              it came from here:
              http://talk.growstuff.org/t/fatal-role-postgres-does-not-exist/216/4






              share|improve this answer





















              • Works for me too! You saved my bacon.
                – Dave Munger
                Jan 6 '16 at 22:22






              • 1




                I get role "me" does not exist
                – SuperUberDuper
                Feb 29 '16 at 22:52















              up vote
              15
              down vote













              For me, this code worked:



              /Applications/Postgres.app/Contents/Versions/9.4/bin/createuser -s postgres


              it came from here:
              http://talk.growstuff.org/t/fatal-role-postgres-does-not-exist/216/4






              share|improve this answer





















              • Works for me too! You saved my bacon.
                – Dave Munger
                Jan 6 '16 at 22:22






              • 1




                I get role "me" does not exist
                – SuperUberDuper
                Feb 29 '16 at 22:52













              up vote
              15
              down vote










              up vote
              15
              down vote









              For me, this code worked:



              /Applications/Postgres.app/Contents/Versions/9.4/bin/createuser -s postgres


              it came from here:
              http://talk.growstuff.org/t/fatal-role-postgres-does-not-exist/216/4






              share|improve this answer












              For me, this code worked:



              /Applications/Postgres.app/Contents/Versions/9.4/bin/createuser -s postgres


              it came from here:
              http://talk.growstuff.org/t/fatal-role-postgres-does-not-exist/216/4







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 6 '15 at 20:09









              Kevin Zhao

              1,4772915




              1,4772915












              • Works for me too! You saved my bacon.
                – Dave Munger
                Jan 6 '16 at 22:22






              • 1




                I get role "me" does not exist
                – SuperUberDuper
                Feb 29 '16 at 22:52


















              • Works for me too! You saved my bacon.
                – Dave Munger
                Jan 6 '16 at 22:22






              • 1




                I get role "me" does not exist
                – SuperUberDuper
                Feb 29 '16 at 22:52
















              Works for me too! You saved my bacon.
              – Dave Munger
              Jan 6 '16 at 22:22




              Works for me too! You saved my bacon.
              – Dave Munger
              Jan 6 '16 at 22:22




              1




              1




              I get role "me" does not exist
              – SuperUberDuper
              Feb 29 '16 at 22:52




              I get role "me" does not exist
              – SuperUberDuper
              Feb 29 '16 at 22:52










              up vote
              10
              down vote













              First you need create a user:



              sudo -u postgres createuser --superuser $USER


              After you create a database:



              sudo -u postgres createdb $USER


              Change $USER to your system username.



              You can see the the complete solution here.






              share|improve this answer



























                up vote
                10
                down vote













                First you need create a user:



                sudo -u postgres createuser --superuser $USER


                After you create a database:



                sudo -u postgres createdb $USER


                Change $USER to your system username.



                You can see the the complete solution here.






                share|improve this answer

























                  up vote
                  10
                  down vote










                  up vote
                  10
                  down vote









                  First you need create a user:



                  sudo -u postgres createuser --superuser $USER


                  After you create a database:



                  sudo -u postgres createdb $USER


                  Change $USER to your system username.



                  You can see the the complete solution here.






                  share|improve this answer














                  First you need create a user:



                  sudo -u postgres createuser --superuser $USER


                  After you create a database:



                  sudo -u postgres createdb $USER


                  Change $USER to your system username.



                  You can see the the complete solution here.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 15 '17 at 5:46

























                  answered Jul 29 '15 at 22:54









                  ruzenhack

                  7461616




                  7461616






















                      up vote
                      8
                      down vote













                      I needed to unset $PGUSER:



                      $ unset PGUSER
                      $ createuser -s postgres





                      share|improve this answer

























                        up vote
                        8
                        down vote













                        I needed to unset $PGUSER:



                        $ unset PGUSER
                        $ createuser -s postgres





                        share|improve this answer























                          up vote
                          8
                          down vote










                          up vote
                          8
                          down vote









                          I needed to unset $PGUSER:



                          $ unset PGUSER
                          $ createuser -s postgres





                          share|improve this answer












                          I needed to unset $PGUSER:



                          $ unset PGUSER
                          $ createuser -s postgres






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 2 at 6:54









                          Beau Barker

                          90411217




                          90411217






















                              up vote
                              7
                              down vote













                              Running this on the command line should fix it



                              /Applications/Postgres.app/Contents/Versions/9.4/bin/createdb <Mac OSX Username Here>






                              share|improve this answer





















                              • requires: postgresapp.com
                                – tandy
                                May 25 '15 at 18:59






                              • 1




                                This is the only thing that worked for me. Thank you!
                                – Herb Meehan
                                Aug 24 '15 at 16:01















                              up vote
                              7
                              down vote













                              Running this on the command line should fix it



                              /Applications/Postgres.app/Contents/Versions/9.4/bin/createdb <Mac OSX Username Here>






                              share|improve this answer





















                              • requires: postgresapp.com
                                – tandy
                                May 25 '15 at 18:59






                              • 1




                                This is the only thing that worked for me. Thank you!
                                – Herb Meehan
                                Aug 24 '15 at 16:01













                              up vote
                              7
                              down vote










                              up vote
                              7
                              down vote









                              Running this on the command line should fix it



                              /Applications/Postgres.app/Contents/Versions/9.4/bin/createdb <Mac OSX Username Here>






                              share|improve this answer












                              Running this on the command line should fix it



                              /Applications/Postgres.app/Contents/Versions/9.4/bin/createdb <Mac OSX Username Here>







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Feb 13 '15 at 21:41









                              Alex Levine

                              653812




                              653812












                              • requires: postgresapp.com
                                – tandy
                                May 25 '15 at 18:59






                              • 1




                                This is the only thing that worked for me. Thank you!
                                – Herb Meehan
                                Aug 24 '15 at 16:01


















                              • requires: postgresapp.com
                                – tandy
                                May 25 '15 at 18:59






                              • 1




                                This is the only thing that worked for me. Thank you!
                                – Herb Meehan
                                Aug 24 '15 at 16:01
















                              requires: postgresapp.com
                              – tandy
                              May 25 '15 at 18:59




                              requires: postgresapp.com
                              – tandy
                              May 25 '15 at 18:59




                              1




                              1




                              This is the only thing that worked for me. Thank you!
                              – Herb Meehan
                              Aug 24 '15 at 16:01




                              This is the only thing that worked for me. Thank you!
                              – Herb Meehan
                              Aug 24 '15 at 16:01










                              up vote
                              4
                              down vote













                              Dropping the postgres database doesn't really matter. This database is initially empty and its purpose is simply for the postgres user to have a kind of "home" to connect to, should it need one.



                              Still you may recreate it with the SQL command CREATE DATABASE postgres;



                              Note that the tutorial mentioned in the question is not written with postgres.app in mind.
                              Contrary to PostgreSQL for Unix in general, postgres.app tries to look like a normal application as opposed to a service that would be run by a dedicated postgres user having different privileges than your normal user. postgres.app is run and managed by your own account.



                              So instead of this command: sudo -u postgres psql -U postgres, it would be more in the spirit of postgres.app to just issue: psql, which automatically connects to a database matching your users's name, and with a db account of the same name that happens to be superuser, so it can do anything permissions-wise.






                              share|improve this answer





















                              • Okay. But why do I get an error ERROR: cannot drop the currently open database when I try to delete the user db? So is it not a good practice to use this postgres.app?
                                – user805981
                                Mar 8 '13 at 21:10










                              • You cannot drop a db while connected to it. why would you want to delete it, anyway? It's here for your convenience.
                                – Daniel Vérité
                                Mar 8 '13 at 21:15










                              • I just wanted to see if I could. So it's like a default database correct when I boot up my psql and postgres.app? Now what about the access privileges? I am not able to set them anymore? I see that template0 and template1 has access privileges
                                – user805981
                                Mar 8 '13 at 21:29












                              • @user805981 Postgres.app is for testing and development purposes; it's a PostgreSQL package from Heroku that's designed to make it easier for Mac users developing with Ruby on Rails to test with PostgreSQL instead of the default SQLite. Rails uses tended to test with SQLite and deploy to PostgreSQL which caused all sorts of problems, so Heroku tried to make it easier to test on PostgreSQL too. Postgres.app is fine for testing, but I wouldn't consider using it for production or real data, that's just not what it's for.
                                – Craig Ringer
                                Mar 9 '13 at 0:32















                              up vote
                              4
                              down vote













                              Dropping the postgres database doesn't really matter. This database is initially empty and its purpose is simply for the postgres user to have a kind of "home" to connect to, should it need one.



                              Still you may recreate it with the SQL command CREATE DATABASE postgres;



                              Note that the tutorial mentioned in the question is not written with postgres.app in mind.
                              Contrary to PostgreSQL for Unix in general, postgres.app tries to look like a normal application as opposed to a service that would be run by a dedicated postgres user having different privileges than your normal user. postgres.app is run and managed by your own account.



                              So instead of this command: sudo -u postgres psql -U postgres, it would be more in the spirit of postgres.app to just issue: psql, which automatically connects to a database matching your users's name, and with a db account of the same name that happens to be superuser, so it can do anything permissions-wise.






                              share|improve this answer





















                              • Okay. But why do I get an error ERROR: cannot drop the currently open database when I try to delete the user db? So is it not a good practice to use this postgres.app?
                                – user805981
                                Mar 8 '13 at 21:10










                              • You cannot drop a db while connected to it. why would you want to delete it, anyway? It's here for your convenience.
                                – Daniel Vérité
                                Mar 8 '13 at 21:15










                              • I just wanted to see if I could. So it's like a default database correct when I boot up my psql and postgres.app? Now what about the access privileges? I am not able to set them anymore? I see that template0 and template1 has access privileges
                                – user805981
                                Mar 8 '13 at 21:29












                              • @user805981 Postgres.app is for testing and development purposes; it's a PostgreSQL package from Heroku that's designed to make it easier for Mac users developing with Ruby on Rails to test with PostgreSQL instead of the default SQLite. Rails uses tended to test with SQLite and deploy to PostgreSQL which caused all sorts of problems, so Heroku tried to make it easier to test on PostgreSQL too. Postgres.app is fine for testing, but I wouldn't consider using it for production or real data, that's just not what it's for.
                                – Craig Ringer
                                Mar 9 '13 at 0:32













                              up vote
                              4
                              down vote










                              up vote
                              4
                              down vote









                              Dropping the postgres database doesn't really matter. This database is initially empty and its purpose is simply for the postgres user to have a kind of "home" to connect to, should it need one.



                              Still you may recreate it with the SQL command CREATE DATABASE postgres;



                              Note that the tutorial mentioned in the question is not written with postgres.app in mind.
                              Contrary to PostgreSQL for Unix in general, postgres.app tries to look like a normal application as opposed to a service that would be run by a dedicated postgres user having different privileges than your normal user. postgres.app is run and managed by your own account.



                              So instead of this command: sudo -u postgres psql -U postgres, it would be more in the spirit of postgres.app to just issue: psql, which automatically connects to a database matching your users's name, and with a db account of the same name that happens to be superuser, so it can do anything permissions-wise.






                              share|improve this answer












                              Dropping the postgres database doesn't really matter. This database is initially empty and its purpose is simply for the postgres user to have a kind of "home" to connect to, should it need one.



                              Still you may recreate it with the SQL command CREATE DATABASE postgres;



                              Note that the tutorial mentioned in the question is not written with postgres.app in mind.
                              Contrary to PostgreSQL for Unix in general, postgres.app tries to look like a normal application as opposed to a service that would be run by a dedicated postgres user having different privileges than your normal user. postgres.app is run and managed by your own account.



                              So instead of this command: sudo -u postgres psql -U postgres, it would be more in the spirit of postgres.app to just issue: psql, which automatically connects to a database matching your users's name, and with a db account of the same name that happens to be superuser, so it can do anything permissions-wise.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Mar 8 '13 at 20:53









                              Daniel Vérité

                              38k1082104




                              38k1082104












                              • Okay. But why do I get an error ERROR: cannot drop the currently open database when I try to delete the user db? So is it not a good practice to use this postgres.app?
                                – user805981
                                Mar 8 '13 at 21:10










                              • You cannot drop a db while connected to it. why would you want to delete it, anyway? It's here for your convenience.
                                – Daniel Vérité
                                Mar 8 '13 at 21:15










                              • I just wanted to see if I could. So it's like a default database correct when I boot up my psql and postgres.app? Now what about the access privileges? I am not able to set them anymore? I see that template0 and template1 has access privileges
                                – user805981
                                Mar 8 '13 at 21:29












                              • @user805981 Postgres.app is for testing and development purposes; it's a PostgreSQL package from Heroku that's designed to make it easier for Mac users developing with Ruby on Rails to test with PostgreSQL instead of the default SQLite. Rails uses tended to test with SQLite and deploy to PostgreSQL which caused all sorts of problems, so Heroku tried to make it easier to test on PostgreSQL too. Postgres.app is fine for testing, but I wouldn't consider using it for production or real data, that's just not what it's for.
                                – Craig Ringer
                                Mar 9 '13 at 0:32


















                              • Okay. But why do I get an error ERROR: cannot drop the currently open database when I try to delete the user db? So is it not a good practice to use this postgres.app?
                                – user805981
                                Mar 8 '13 at 21:10










                              • You cannot drop a db while connected to it. why would you want to delete it, anyway? It's here for your convenience.
                                – Daniel Vérité
                                Mar 8 '13 at 21:15










                              • I just wanted to see if I could. So it's like a default database correct when I boot up my psql and postgres.app? Now what about the access privileges? I am not able to set them anymore? I see that template0 and template1 has access privileges
                                – user805981
                                Mar 8 '13 at 21:29












                              • @user805981 Postgres.app is for testing and development purposes; it's a PostgreSQL package from Heroku that's designed to make it easier for Mac users developing with Ruby on Rails to test with PostgreSQL instead of the default SQLite. Rails uses tended to test with SQLite and deploy to PostgreSQL which caused all sorts of problems, so Heroku tried to make it easier to test on PostgreSQL too. Postgres.app is fine for testing, but I wouldn't consider using it for production or real data, that's just not what it's for.
                                – Craig Ringer
                                Mar 9 '13 at 0:32
















                              Okay. But why do I get an error ERROR: cannot drop the currently open database when I try to delete the user db? So is it not a good practice to use this postgres.app?
                              – user805981
                              Mar 8 '13 at 21:10




                              Okay. But why do I get an error ERROR: cannot drop the currently open database when I try to delete the user db? So is it not a good practice to use this postgres.app?
                              – user805981
                              Mar 8 '13 at 21:10












                              You cannot drop a db while connected to it. why would you want to delete it, anyway? It's here for your convenience.
                              – Daniel Vérité
                              Mar 8 '13 at 21:15




                              You cannot drop a db while connected to it. why would you want to delete it, anyway? It's here for your convenience.
                              – Daniel Vérité
                              Mar 8 '13 at 21:15












                              I just wanted to see if I could. So it's like a default database correct when I boot up my psql and postgres.app? Now what about the access privileges? I am not able to set them anymore? I see that template0 and template1 has access privileges
                              – user805981
                              Mar 8 '13 at 21:29






                              I just wanted to see if I could. So it's like a default database correct when I boot up my psql and postgres.app? Now what about the access privileges? I am not able to set them anymore? I see that template0 and template1 has access privileges
                              – user805981
                              Mar 8 '13 at 21:29














                              @user805981 Postgres.app is for testing and development purposes; it's a PostgreSQL package from Heroku that's designed to make it easier for Mac users developing with Ruby on Rails to test with PostgreSQL instead of the default SQLite. Rails uses tended to test with SQLite and deploy to PostgreSQL which caused all sorts of problems, so Heroku tried to make it easier to test on PostgreSQL too. Postgres.app is fine for testing, but I wouldn't consider using it for production or real data, that's just not what it's for.
                              – Craig Ringer
                              Mar 9 '13 at 0:32




                              @user805981 Postgres.app is for testing and development purposes; it's a PostgreSQL package from Heroku that's designed to make it easier for Mac users developing with Ruby on Rails to test with PostgreSQL instead of the default SQLite. Rails uses tended to test with SQLite and deploy to PostgreSQL which caused all sorts of problems, so Heroku tried to make it easier to test on PostgreSQL too. Postgres.app is fine for testing, but I wouldn't consider using it for production or real data, that's just not what it's for.
                              – Craig Ringer
                              Mar 9 '13 at 0:32










                              up vote
                              3
                              down vote













                              For what it is worth, i have ubuntu and many packages installed and it went in conflict with it.



                              For me the right answer was:



                              sudo -i -u postgres-xc
                              psql





                              share|improve this answer

























                                up vote
                                3
                                down vote













                                For what it is worth, i have ubuntu and many packages installed and it went in conflict with it.



                                For me the right answer was:



                                sudo -i -u postgres-xc
                                psql





                                share|improve this answer























                                  up vote
                                  3
                                  down vote










                                  up vote
                                  3
                                  down vote









                                  For what it is worth, i have ubuntu and many packages installed and it went in conflict with it.



                                  For me the right answer was:



                                  sudo -i -u postgres-xc
                                  psql





                                  share|improve this answer












                                  For what it is worth, i have ubuntu and many packages installed and it went in conflict with it.



                                  For me the right answer was:



                                  sudo -i -u postgres-xc
                                  psql






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Jan 11 '17 at 15:37









                                  softwareplay

                                  75631441




                                  75631441






















                                      up vote
                                      1
                                      down vote













                                      This is the only one that fixed it for me :



                                      createuser -s -U $USER





                                      share|improve this answer

















                                      • 1




                                        This makes the current user a system superuser rather than just a postgres superuser. I would say this would be generally a bad idea as it circumvents the usual security policies. You should user sudo to gain temporary superuser privileges.
                                        – Sean Dawson
                                        Mar 29 '16 at 21:54















                                      up vote
                                      1
                                      down vote













                                      This is the only one that fixed it for me :



                                      createuser -s -U $USER





                                      share|improve this answer

















                                      • 1




                                        This makes the current user a system superuser rather than just a postgres superuser. I would say this would be generally a bad idea as it circumvents the usual security policies. You should user sudo to gain temporary superuser privileges.
                                        – Sean Dawson
                                        Mar 29 '16 at 21:54













                                      up vote
                                      1
                                      down vote










                                      up vote
                                      1
                                      down vote









                                      This is the only one that fixed it for me :



                                      createuser -s -U $USER





                                      share|improve this answer












                                      This is the only one that fixed it for me :



                                      createuser -s -U $USER






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 2 '16 at 0:10









                                      Bax

                                      2,53622447




                                      2,53622447








                                      • 1




                                        This makes the current user a system superuser rather than just a postgres superuser. I would say this would be generally a bad idea as it circumvents the usual security policies. You should user sudo to gain temporary superuser privileges.
                                        – Sean Dawson
                                        Mar 29 '16 at 21:54














                                      • 1




                                        This makes the current user a system superuser rather than just a postgres superuser. I would say this would be generally a bad idea as it circumvents the usual security policies. You should user sudo to gain temporary superuser privileges.
                                        – Sean Dawson
                                        Mar 29 '16 at 21:54








                                      1




                                      1




                                      This makes the current user a system superuser rather than just a postgres superuser. I would say this would be generally a bad idea as it circumvents the usual security policies. You should user sudo to gain temporary superuser privileges.
                                      – Sean Dawson
                                      Mar 29 '16 at 21:54




                                      This makes the current user a system superuser rather than just a postgres superuser. I would say this would be generally a bad idea as it circumvents the usual security policies. You should user sudo to gain temporary superuser privileges.
                                      – Sean Dawson
                                      Mar 29 '16 at 21:54










                                      up vote
                                      1
                                      down vote













                                      On Ubuntu system, I purged the PostgreSQL and re-installed it. All the databases are restored.
                                      This solved the problem for me.



                                      Advice - Take the backup of the databases to be on the safer side.






                                      share|improve this answer








                                      New contributor




                                      Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.






















                                        up vote
                                        1
                                        down vote













                                        On Ubuntu system, I purged the PostgreSQL and re-installed it. All the databases are restored.
                                        This solved the problem for me.



                                        Advice - Take the backup of the databases to be on the safer side.






                                        share|improve this answer








                                        New contributor




                                        Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                        Check out our Code of Conduct.




















                                          up vote
                                          1
                                          down vote










                                          up vote
                                          1
                                          down vote









                                          On Ubuntu system, I purged the PostgreSQL and re-installed it. All the databases are restored.
                                          This solved the problem for me.



                                          Advice - Take the backup of the databases to be on the safer side.






                                          share|improve this answer








                                          New contributor




                                          Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.









                                          On Ubuntu system, I purged the PostgreSQL and re-installed it. All the databases are restored.
                                          This solved the problem for me.



                                          Advice - Take the backup of the databases to be on the safer side.







                                          share|improve this answer








                                          New contributor




                                          Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.









                                          share|improve this answer



                                          share|improve this answer






                                          New contributor




                                          Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.









                                          answered Nov 20 at 5:52









                                          Gaurav Neema

                                          826




                                          826




                                          New contributor




                                          Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.





                                          New contributor





                                          Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.






                                          Gaurav Neema is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                          Check out our Code of Conduct.






















                                              up vote
                                              0
                                              down vote













                                              I don't think that sudo is needed here because psql -l returns a list of databases. This tells me that initdb was run under the user's current user, not under the postgres user.



                                              You can just:



                                              psql


                                              And continue the tutorial.



                                              I would suggest A.H's general points of creating the postgres user and db because many applications may expect this to exist.



                                              A brief explanation:



                                              PostgreSQL will not run with administrative access to the operating system. Instead it runs with an ordinary user, and in order to support peer authentication (asking the OS who is trying to connect) it creates a user and db with the user that runs the initialization process. In this case it was your normal user.






                                              share|improve this answer





















                                              • clears few important distinction in postgres. Thank you.
                                                – imsrgadich
                                                Mar 27 at 14:05















                                              up vote
                                              0
                                              down vote













                                              I don't think that sudo is needed here because psql -l returns a list of databases. This tells me that initdb was run under the user's current user, not under the postgres user.



                                              You can just:



                                              psql


                                              And continue the tutorial.



                                              I would suggest A.H's general points of creating the postgres user and db because many applications may expect this to exist.



                                              A brief explanation:



                                              PostgreSQL will not run with administrative access to the operating system. Instead it runs with an ordinary user, and in order to support peer authentication (asking the OS who is trying to connect) it creates a user and db with the user that runs the initialization process. In this case it was your normal user.






                                              share|improve this answer





















                                              • clears few important distinction in postgres. Thank you.
                                                – imsrgadich
                                                Mar 27 at 14:05













                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              I don't think that sudo is needed here because psql -l returns a list of databases. This tells me that initdb was run under the user's current user, not under the postgres user.



                                              You can just:



                                              psql


                                              And continue the tutorial.



                                              I would suggest A.H's general points of creating the postgres user and db because many applications may expect this to exist.



                                              A brief explanation:



                                              PostgreSQL will not run with administrative access to the operating system. Instead it runs with an ordinary user, and in order to support peer authentication (asking the OS who is trying to connect) it creates a user and db with the user that runs the initialization process. In this case it was your normal user.






                                              share|improve this answer












                                              I don't think that sudo is needed here because psql -l returns a list of databases. This tells me that initdb was run under the user's current user, not under the postgres user.



                                              You can just:



                                              psql


                                              And continue the tutorial.



                                              I would suggest A.H's general points of creating the postgres user and db because many applications may expect this to exist.



                                              A brief explanation:



                                              PostgreSQL will not run with administrative access to the operating system. Instead it runs with an ordinary user, and in order to support peer authentication (asking the OS who is trying to connect) it creates a user and db with the user that runs the initialization process. In this case it was your normal user.







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Mar 9 '13 at 14:36









                                              Chris Travers

                                              18.5k642141




                                              18.5k642141












                                              • clears few important distinction in postgres. Thank you.
                                                – imsrgadich
                                                Mar 27 at 14:05


















                                              • clears few important distinction in postgres. Thank you.
                                                – imsrgadich
                                                Mar 27 at 14:05
















                                              clears few important distinction in postgres. Thank you.
                                              – imsrgadich
                                              Mar 27 at 14:05




                                              clears few important distinction in postgres. Thank you.
                                              – imsrgadich
                                              Mar 27 at 14:05










                                              up vote
                                              0
                                              down vote













                                              I became stuck on this issue having executed brew services stop postgresql the day prior.
                                              The day following: brew services start postgresql would not work. This is because as is shown when you install using homebrew. postgresql uses a launchd ... which loads when your computer is powered on.

                                              resolution:
                                              brew services start postgresql
                                              Restart your computer.






                                              share|improve this answer

























                                                up vote
                                                0
                                                down vote













                                                I became stuck on this issue having executed brew services stop postgresql the day prior.
                                                The day following: brew services start postgresql would not work. This is because as is shown when you install using homebrew. postgresql uses a launchd ... which loads when your computer is powered on.

                                                resolution:
                                                brew services start postgresql
                                                Restart your computer.






                                                share|improve this answer























                                                  up vote
                                                  0
                                                  down vote










                                                  up vote
                                                  0
                                                  down vote









                                                  I became stuck on this issue having executed brew services stop postgresql the day prior.
                                                  The day following: brew services start postgresql would not work. This is because as is shown when you install using homebrew. postgresql uses a launchd ... which loads when your computer is powered on.

                                                  resolution:
                                                  brew services start postgresql
                                                  Restart your computer.






                                                  share|improve this answer












                                                  I became stuck on this issue having executed brew services stop postgresql the day prior.
                                                  The day following: brew services start postgresql would not work. This is because as is shown when you install using homebrew. postgresql uses a launchd ... which loads when your computer is powered on.

                                                  resolution:
                                                  brew services start postgresql
                                                  Restart your computer.







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Jun 26 '17 at 12:33









                                                  Michael Dimmitt

                                                  299215




                                                  299215






















                                                      up vote
                                                      0
                                                      down vote













                                                      The du command return:




                                                      Role name = postgres@implicit_files




                                                      And that command postgres=# password postgres return error:




                                                      ERROR: role "postgres" does not exist.




                                                      But that postgres=# password postgres@implicit_files run fine.



                                                      Also after sudo -u postgres createuser -s postgres the first variant also work.






                                                      share|improve this answer



























                                                        up vote
                                                        0
                                                        down vote













                                                        The du command return:




                                                        Role name = postgres@implicit_files




                                                        And that command postgres=# password postgres return error:




                                                        ERROR: role "postgres" does not exist.




                                                        But that postgres=# password postgres@implicit_files run fine.



                                                        Also after sudo -u postgres createuser -s postgres the first variant also work.






                                                        share|improve this answer

























                                                          up vote
                                                          0
                                                          down vote










                                                          up vote
                                                          0
                                                          down vote









                                                          The du command return:




                                                          Role name = postgres@implicit_files




                                                          And that command postgres=# password postgres return error:




                                                          ERROR: role "postgres" does not exist.




                                                          But that postgres=# password postgres@implicit_files run fine.



                                                          Also after sudo -u postgres createuser -s postgres the first variant also work.






                                                          share|improve this answer














                                                          The du command return:




                                                          Role name = postgres@implicit_files




                                                          And that command postgres=# password postgres return error:




                                                          ERROR: role "postgres" does not exist.




                                                          But that postgres=# password postgres@implicit_files run fine.



                                                          Also after sudo -u postgres createuser -s postgres the first variant also work.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Jun 28 at 8:39

























                                                          answered Jun 28 at 8:32









                                                          Michael

                                                          8061523




                                                          8061523






























                                                               

                                                              draft saved


                                                              draft discarded



















































                                                               


                                                              draft saved


                                                              draft discarded














                                                              StackExchange.ready(
                                                              function () {
                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f15301826%2fpsql-fatal-role-postgres-does-not-exist%23new-answer', 'question_page');
                                                              }
                                                              );

                                                              Post as a guest















                                                              Required, but never shown





















































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown

































                                                              Required, but never shown














                                                              Required, but never shown












                                                              Required, but never shown







                                                              Required, but never shown







                                                              Popular posts from this blog

                                                              Ottavio Pratesi

                                                              Tricia Helfer

                                                              15 giugno