Postgresql user “postgres” requires password in order to create db











up vote
-1
down vote

favorite












I am running centOS 7 and trying to create a postgresql database



I entered to following to install and initiate database



yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

sudo yum install postgresql11

sudo yum install postgresql11-server

sudo /usr/pgsql-11/bin/postgresql-11-setup initdb

sudo systemctl enable postgresql-11

sudo systemctl start postgresql-11


so after this i try to create a database by entering



sudo createdb mydb


receive:



createdb: could not connect to database template1: FATAL:  role "root" does not exist


so now i realize i need to be on the postgre user



and cannot create a db with this command:



sudo -u postgres createdb mydb


Recieve:



could not change directory to "/home/<user>": Permission denied


I am able to get the postgre prompt by entering the following



sudo -u postgres -i
psql


but when i enter sudo -u postgres -1 i get a new bash prompt -bash-4.2$



when i try to create a database in this prompt with sudo createdb mydb it asks for a password for postgres and can't go on from there,
what is this password? i read that by default it shouldn't










share|improve this question




























    up vote
    -1
    down vote

    favorite












    I am running centOS 7 and trying to create a postgresql database



    I entered to following to install and initiate database



    yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

    sudo yum install postgresql11

    sudo yum install postgresql11-server

    sudo /usr/pgsql-11/bin/postgresql-11-setup initdb

    sudo systemctl enable postgresql-11

    sudo systemctl start postgresql-11


    so after this i try to create a database by entering



    sudo createdb mydb


    receive:



    createdb: could not connect to database template1: FATAL:  role "root" does not exist


    so now i realize i need to be on the postgre user



    and cannot create a db with this command:



    sudo -u postgres createdb mydb


    Recieve:



    could not change directory to "/home/<user>": Permission denied


    I am able to get the postgre prompt by entering the following



    sudo -u postgres -i
    psql


    but when i enter sudo -u postgres -1 i get a new bash prompt -bash-4.2$



    when i try to create a database in this prompt with sudo createdb mydb it asks for a password for postgres and can't go on from there,
    what is this password? i read that by default it shouldn't










    share|improve this question


























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I am running centOS 7 and trying to create a postgresql database



      I entered to following to install and initiate database



      yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

      sudo yum install postgresql11

      sudo yum install postgresql11-server

      sudo /usr/pgsql-11/bin/postgresql-11-setup initdb

      sudo systemctl enable postgresql-11

      sudo systemctl start postgresql-11


      so after this i try to create a database by entering



      sudo createdb mydb


      receive:



      createdb: could not connect to database template1: FATAL:  role "root" does not exist


      so now i realize i need to be on the postgre user



      and cannot create a db with this command:



      sudo -u postgres createdb mydb


      Recieve:



      could not change directory to "/home/<user>": Permission denied


      I am able to get the postgre prompt by entering the following



      sudo -u postgres -i
      psql


      but when i enter sudo -u postgres -1 i get a new bash prompt -bash-4.2$



      when i try to create a database in this prompt with sudo createdb mydb it asks for a password for postgres and can't go on from there,
      what is this password? i read that by default it shouldn't










      share|improve this question















      I am running centOS 7 and trying to create a postgresql database



      I entered to following to install and initiate database



      yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

      sudo yum install postgresql11

      sudo yum install postgresql11-server

      sudo /usr/pgsql-11/bin/postgresql-11-setup initdb

      sudo systemctl enable postgresql-11

      sudo systemctl start postgresql-11


      so after this i try to create a database by entering



      sudo createdb mydb


      receive:



      createdb: could not connect to database template1: FATAL:  role "root" does not exist


      so now i realize i need to be on the postgre user



      and cannot create a db with this command:



      sudo -u postgres createdb mydb


      Recieve:



      could not change directory to "/home/<user>": Permission denied


      I am able to get the postgre prompt by entering the following



      sudo -u postgres -i
      psql


      but when i enter sudo -u postgres -1 i get a new bash prompt -bash-4.2$



      when i try to create a database in this prompt with sudo createdb mydb it asks for a password for postgres and can't go on from there,
      what is this password? i read that by default it shouldn't







      linux postgresql centos7






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 17:03









      a_horse_with_no_name

      286k45432527




      286k45432527










      asked Nov 7 at 16:10









      Mfreeman

      5912




      5912
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Did you try
          sudo -i -u postgres
          psql CREATE DATABASE yourbase;
          c yourbase ?






          share|improve this answer





















          • Whoops, i dont know why i didnt try to create it from the prompt. that works, thanks
            – Mfreeman
            Nov 7 at 16:15













          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%2f53193382%2fpostgresql-user-postgres-requires-password-in-order-to-create-db%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          Did you try
          sudo -i -u postgres
          psql CREATE DATABASE yourbase;
          c yourbase ?






          share|improve this answer





















          • Whoops, i dont know why i didnt try to create it from the prompt. that works, thanks
            – Mfreeman
            Nov 7 at 16:15

















          up vote
          2
          down vote



          accepted










          Did you try
          sudo -i -u postgres
          psql CREATE DATABASE yourbase;
          c yourbase ?






          share|improve this answer





















          • Whoops, i dont know why i didnt try to create it from the prompt. that works, thanks
            – Mfreeman
            Nov 7 at 16:15















          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          Did you try
          sudo -i -u postgres
          psql CREATE DATABASE yourbase;
          c yourbase ?






          share|improve this answer












          Did you try
          sudo -i -u postgres
          psql CREATE DATABASE yourbase;
          c yourbase ?







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 16:12









          G.D

          535




          535












          • Whoops, i dont know why i didnt try to create it from the prompt. that works, thanks
            – Mfreeman
            Nov 7 at 16:15




















          • Whoops, i dont know why i didnt try to create it from the prompt. that works, thanks
            – Mfreeman
            Nov 7 at 16:15


















          Whoops, i dont know why i didnt try to create it from the prompt. that works, thanks
          – Mfreeman
          Nov 7 at 16:15






          Whoops, i dont know why i didnt try to create it from the prompt. that works, thanks
          – Mfreeman
          Nov 7 at 16:15




















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53193382%2fpostgresql-user-postgres-requires-password-in-order-to-create-db%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







          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini