Permanently change permissions of /var/run/postgresql

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












2















On Linux Mint 17.0 Cinnamon Edition, I want to use /var/run/postgresql as the unix_socket_directories option for all of my postgres databases.



Whenever I run the command pg_ctl -D postgres-data -o '-F -p 33311' start to start my local database, I get the error FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.33311.lock": Permission denied.



As many answers across AskUbuntu, StackOverflow and various forums suggest, I have to run sudo chmod 777 /var/run/postgresql or sudo chown -R $USER:$USER /var/run/postgresql to change the permissions of the directory so that I can write to it. Then I am able to start my database. However, every time I reboot, the permissions go away; the directory is no longer world-writable and the user postgres-xc reclaims user and group ownership over the directory.



Neither sudo adduser $USER postgres or sudo adduser $USER postgres-xc alleviates the permissions issue.



I tried doing a clean install as described here, but I still have the issue on reboot.



I've tried changing the value of unix_socket_directories to /tmp in ./postgres-data/postgresql.conf (the local database config file), and this allows me to start that particular database without having to update permissions on every reboot. However, I also have a script which uses pg_ctl -D $DIR initdb && pg_ctl -D $DIR start to setup and start databases on the fly. As such, a default postgresql.conf config file is used for these databases, so unix_socket_directories is the unwritable /var/run/postgresql and I get permission denied errors when running that script. Manually/programmatically editing these configs on-the-fly to use unix_socket_directories = '/tmp' is... undesirable.



I know that I could use the -o flag with pg_ctl to override the unix_socket_directories option to /tmp, but this script is shared by other developers who do not use Ubuntu, so I would not necessarily want to restrict everyone to using the /tmp directory, especially if their configurations differed slightly. I would prefer everyone use the default location for their installation. Personally, I would also prefer to keep the default directory for general compatibility with other Ubuntu packages; e.g., pgadmin looks at /var/run/postgresql for a lock file by default.



I have also tried editing /etc/postgresql/9.3/main/pg_ctl.conf in an attempt to automatically pass set these options whenever I use pg_ctl:



# Automatic pg_ctl configuration
# This configuration file contains cluster specific options to be passed to
# pg_ctl(1).

pg_ctl_options = '-o "-c unix_socket_directories=/tmp -c unix_socket_group=jackson -c unix_socket_permissions=0777"'


But that did not have any effect.



Please advise on how I can use /var/run/postgresql as my unix_socket_directories option for all of my postgres databases without having to run sudo chown -R $USER:$USER /var/run/postgresql every time I restart my system. Thanks.










share|improve this question
























  • What kind of file system is sitting in? When you reboot/restart the system, does this directory exist? Just wondering if this is sitting in a tmpfs file system or similar.

    – user1174838
    Jun 2 '15 at 0:29











  • Whatever the default file system is for a user installation of Linux Mint 17.0; ext4 I think.

    – Jackson
    Jun 2 '15 at 0:32











  • After a reboot, does the directory exist?

    – user1174838
    Jun 2 '15 at 1:19











  • Yes, the directory exists.

    – Jackson
    Jun 2 '15 at 2:14











  • X-post from askubuntu.com/q/631112/75715

    – Craig Ringer
    Jun 2 '15 at 2:19















2















On Linux Mint 17.0 Cinnamon Edition, I want to use /var/run/postgresql as the unix_socket_directories option for all of my postgres databases.



Whenever I run the command pg_ctl -D postgres-data -o '-F -p 33311' start to start my local database, I get the error FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.33311.lock": Permission denied.



As many answers across AskUbuntu, StackOverflow and various forums suggest, I have to run sudo chmod 777 /var/run/postgresql or sudo chown -R $USER:$USER /var/run/postgresql to change the permissions of the directory so that I can write to it. Then I am able to start my database. However, every time I reboot, the permissions go away; the directory is no longer world-writable and the user postgres-xc reclaims user and group ownership over the directory.



Neither sudo adduser $USER postgres or sudo adduser $USER postgres-xc alleviates the permissions issue.



I tried doing a clean install as described here, but I still have the issue on reboot.



I've tried changing the value of unix_socket_directories to /tmp in ./postgres-data/postgresql.conf (the local database config file), and this allows me to start that particular database without having to update permissions on every reboot. However, I also have a script which uses pg_ctl -D $DIR initdb && pg_ctl -D $DIR start to setup and start databases on the fly. As such, a default postgresql.conf config file is used for these databases, so unix_socket_directories is the unwritable /var/run/postgresql and I get permission denied errors when running that script. Manually/programmatically editing these configs on-the-fly to use unix_socket_directories = '/tmp' is... undesirable.



I know that I could use the -o flag with pg_ctl to override the unix_socket_directories option to /tmp, but this script is shared by other developers who do not use Ubuntu, so I would not necessarily want to restrict everyone to using the /tmp directory, especially if their configurations differed slightly. I would prefer everyone use the default location for their installation. Personally, I would also prefer to keep the default directory for general compatibility with other Ubuntu packages; e.g., pgadmin looks at /var/run/postgresql for a lock file by default.



I have also tried editing /etc/postgresql/9.3/main/pg_ctl.conf in an attempt to automatically pass set these options whenever I use pg_ctl:



# Automatic pg_ctl configuration
# This configuration file contains cluster specific options to be passed to
# pg_ctl(1).

pg_ctl_options = '-o "-c unix_socket_directories=/tmp -c unix_socket_group=jackson -c unix_socket_permissions=0777"'


But that did not have any effect.



Please advise on how I can use /var/run/postgresql as my unix_socket_directories option for all of my postgres databases without having to run sudo chown -R $USER:$USER /var/run/postgresql every time I restart my system. Thanks.










share|improve this question
























  • What kind of file system is sitting in? When you reboot/restart the system, does this directory exist? Just wondering if this is sitting in a tmpfs file system or similar.

    – user1174838
    Jun 2 '15 at 0:29











  • Whatever the default file system is for a user installation of Linux Mint 17.0; ext4 I think.

    – Jackson
    Jun 2 '15 at 0:32











  • After a reboot, does the directory exist?

    – user1174838
    Jun 2 '15 at 1:19











  • Yes, the directory exists.

    – Jackson
    Jun 2 '15 at 2:14











  • X-post from askubuntu.com/q/631112/75715

    – Craig Ringer
    Jun 2 '15 at 2:19













2












2








2


1






On Linux Mint 17.0 Cinnamon Edition, I want to use /var/run/postgresql as the unix_socket_directories option for all of my postgres databases.



Whenever I run the command pg_ctl -D postgres-data -o '-F -p 33311' start to start my local database, I get the error FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.33311.lock": Permission denied.



As many answers across AskUbuntu, StackOverflow and various forums suggest, I have to run sudo chmod 777 /var/run/postgresql or sudo chown -R $USER:$USER /var/run/postgresql to change the permissions of the directory so that I can write to it. Then I am able to start my database. However, every time I reboot, the permissions go away; the directory is no longer world-writable and the user postgres-xc reclaims user and group ownership over the directory.



Neither sudo adduser $USER postgres or sudo adduser $USER postgres-xc alleviates the permissions issue.



I tried doing a clean install as described here, but I still have the issue on reboot.



I've tried changing the value of unix_socket_directories to /tmp in ./postgres-data/postgresql.conf (the local database config file), and this allows me to start that particular database without having to update permissions on every reboot. However, I also have a script which uses pg_ctl -D $DIR initdb && pg_ctl -D $DIR start to setup and start databases on the fly. As such, a default postgresql.conf config file is used for these databases, so unix_socket_directories is the unwritable /var/run/postgresql and I get permission denied errors when running that script. Manually/programmatically editing these configs on-the-fly to use unix_socket_directories = '/tmp' is... undesirable.



I know that I could use the -o flag with pg_ctl to override the unix_socket_directories option to /tmp, but this script is shared by other developers who do not use Ubuntu, so I would not necessarily want to restrict everyone to using the /tmp directory, especially if their configurations differed slightly. I would prefer everyone use the default location for their installation. Personally, I would also prefer to keep the default directory for general compatibility with other Ubuntu packages; e.g., pgadmin looks at /var/run/postgresql for a lock file by default.



I have also tried editing /etc/postgresql/9.3/main/pg_ctl.conf in an attempt to automatically pass set these options whenever I use pg_ctl:



# Automatic pg_ctl configuration
# This configuration file contains cluster specific options to be passed to
# pg_ctl(1).

pg_ctl_options = '-o "-c unix_socket_directories=/tmp -c unix_socket_group=jackson -c unix_socket_permissions=0777"'


But that did not have any effect.



Please advise on how I can use /var/run/postgresql as my unix_socket_directories option for all of my postgres databases without having to run sudo chown -R $USER:$USER /var/run/postgresql every time I restart my system. Thanks.










share|improve this question
















On Linux Mint 17.0 Cinnamon Edition, I want to use /var/run/postgresql as the unix_socket_directories option for all of my postgres databases.



Whenever I run the command pg_ctl -D postgres-data -o '-F -p 33311' start to start my local database, I get the error FATAL: could not create lock file "/var/run/postgresql/.s.PGSQL.33311.lock": Permission denied.



As many answers across AskUbuntu, StackOverflow and various forums suggest, I have to run sudo chmod 777 /var/run/postgresql or sudo chown -R $USER:$USER /var/run/postgresql to change the permissions of the directory so that I can write to it. Then I am able to start my database. However, every time I reboot, the permissions go away; the directory is no longer world-writable and the user postgres-xc reclaims user and group ownership over the directory.



Neither sudo adduser $USER postgres or sudo adduser $USER postgres-xc alleviates the permissions issue.



I tried doing a clean install as described here, but I still have the issue on reboot.



I've tried changing the value of unix_socket_directories to /tmp in ./postgres-data/postgresql.conf (the local database config file), and this allows me to start that particular database without having to update permissions on every reboot. However, I also have a script which uses pg_ctl -D $DIR initdb && pg_ctl -D $DIR start to setup and start databases on the fly. As such, a default postgresql.conf config file is used for these databases, so unix_socket_directories is the unwritable /var/run/postgresql and I get permission denied errors when running that script. Manually/programmatically editing these configs on-the-fly to use unix_socket_directories = '/tmp' is... undesirable.



I know that I could use the -o flag with pg_ctl to override the unix_socket_directories option to /tmp, but this script is shared by other developers who do not use Ubuntu, so I would not necessarily want to restrict everyone to using the /tmp directory, especially if their configurations differed slightly. I would prefer everyone use the default location for their installation. Personally, I would also prefer to keep the default directory for general compatibility with other Ubuntu packages; e.g., pgadmin looks at /var/run/postgresql for a lock file by default.



I have also tried editing /etc/postgresql/9.3/main/pg_ctl.conf in an attempt to automatically pass set these options whenever I use pg_ctl:



# Automatic pg_ctl configuration
# This configuration file contains cluster specific options to be passed to
# pg_ctl(1).

pg_ctl_options = '-o "-c unix_socket_directories=/tmp -c unix_socket_group=jackson -c unix_socket_permissions=0777"'


But that did not have any effect.



Please advise on how I can use /var/run/postgresql as my unix_socket_directories option for all of my postgres databases without having to run sudo chown -R $USER:$USER /var/run/postgresql every time I restart my system. Thanks.







permissions linux-mint chmod chown postgresql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:39









Community

1




1










asked Jun 1 '15 at 22:58









JacksonJackson

23629




23629












  • What kind of file system is sitting in? When you reboot/restart the system, does this directory exist? Just wondering if this is sitting in a tmpfs file system or similar.

    – user1174838
    Jun 2 '15 at 0:29











  • Whatever the default file system is for a user installation of Linux Mint 17.0; ext4 I think.

    – Jackson
    Jun 2 '15 at 0:32











  • After a reboot, does the directory exist?

    – user1174838
    Jun 2 '15 at 1:19











  • Yes, the directory exists.

    – Jackson
    Jun 2 '15 at 2:14











  • X-post from askubuntu.com/q/631112/75715

    – Craig Ringer
    Jun 2 '15 at 2:19

















  • What kind of file system is sitting in? When you reboot/restart the system, does this directory exist? Just wondering if this is sitting in a tmpfs file system or similar.

    – user1174838
    Jun 2 '15 at 0:29











  • Whatever the default file system is for a user installation of Linux Mint 17.0; ext4 I think.

    – Jackson
    Jun 2 '15 at 0:32











  • After a reboot, does the directory exist?

    – user1174838
    Jun 2 '15 at 1:19











  • Yes, the directory exists.

    – Jackson
    Jun 2 '15 at 2:14











  • X-post from askubuntu.com/q/631112/75715

    – Craig Ringer
    Jun 2 '15 at 2:19
















What kind of file system is sitting in? When you reboot/restart the system, does this directory exist? Just wondering if this is sitting in a tmpfs file system or similar.

– user1174838
Jun 2 '15 at 0:29





What kind of file system is sitting in? When you reboot/restart the system, does this directory exist? Just wondering if this is sitting in a tmpfs file system or similar.

– user1174838
Jun 2 '15 at 0:29













Whatever the default file system is for a user installation of Linux Mint 17.0; ext4 I think.

– Jackson
Jun 2 '15 at 0:32





Whatever the default file system is for a user installation of Linux Mint 17.0; ext4 I think.

– Jackson
Jun 2 '15 at 0:32













After a reboot, does the directory exist?

– user1174838
Jun 2 '15 at 1:19





After a reboot, does the directory exist?

– user1174838
Jun 2 '15 at 1:19













Yes, the directory exists.

– Jackson
Jun 2 '15 at 2:14





Yes, the directory exists.

– Jackson
Jun 2 '15 at 2:14













X-post from askubuntu.com/q/631112/75715

– Craig Ringer
Jun 2 '15 at 2:19





X-post from askubuntu.com/q/631112/75715

– Craig Ringer
Jun 2 '15 at 2:19










3 Answers
3






active

oldest

votes


















1














Run the following to reclaim the directory (immediately and on subsequent boots):



service='reclaim-postgresql'
service_file="/etc/init.d/$service"

echo "#!/bin/sh
set -e

### BEGIN INIT INFO
# Provides: $service
# Required-Start: $postgres-xc
# Required-Stop: $postgres-xc
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Reclaim /var/run/postgresql
### END INIT INFO

chown -R $USER:$USER /var/run/postgresql"
| sudo tee "$service_file"
sudo chmod +x "$service_file"
sudo update-rc.d "$service" defaults
sudo service "$service" start


Note that when running sudo apt-get upgrade to update postgres, you may need to temporarily sudo chown -R postgres:postgres /var/run/postgresql in order for the upgrade to succeed.






share|improve this answer
































    0














    Depending on your init system, add the chown/chmod command in the relevant init script for PostgreSQL such as /etc/init.d/postgresql.






    share|improve this answer






























      0














      Permissions for /var/run/postgresql are taken from /usr/lib/tmpfiles.d/postgresql.conf






      share|improve this answer






















        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        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',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        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%2funix.stackexchange.com%2fquestions%2f206917%2fpermanently-change-permissions-of-var-run-postgresql%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        Run the following to reclaim the directory (immediately and on subsequent boots):



        service='reclaim-postgresql'
        service_file="/etc/init.d/$service"

        echo "#!/bin/sh
        set -e

        ### BEGIN INIT INFO
        # Provides: $service
        # Required-Start: $postgres-xc
        # Required-Stop: $postgres-xc
        # Default-Start: 2 3 4 5
        # Default-Stop: 0 1 6
        # Short-Description: Reclaim /var/run/postgresql
        ### END INIT INFO

        chown -R $USER:$USER /var/run/postgresql"
        | sudo tee "$service_file"
        sudo chmod +x "$service_file"
        sudo update-rc.d "$service" defaults
        sudo service "$service" start


        Note that when running sudo apt-get upgrade to update postgres, you may need to temporarily sudo chown -R postgres:postgres /var/run/postgresql in order for the upgrade to succeed.






        share|improve this answer





























          1














          Run the following to reclaim the directory (immediately and on subsequent boots):



          service='reclaim-postgresql'
          service_file="/etc/init.d/$service"

          echo "#!/bin/sh
          set -e

          ### BEGIN INIT INFO
          # Provides: $service
          # Required-Start: $postgres-xc
          # Required-Stop: $postgres-xc
          # Default-Start: 2 3 4 5
          # Default-Stop: 0 1 6
          # Short-Description: Reclaim /var/run/postgresql
          ### END INIT INFO

          chown -R $USER:$USER /var/run/postgresql"
          | sudo tee "$service_file"
          sudo chmod +x "$service_file"
          sudo update-rc.d "$service" defaults
          sudo service "$service" start


          Note that when running sudo apt-get upgrade to update postgres, you may need to temporarily sudo chown -R postgres:postgres /var/run/postgresql in order for the upgrade to succeed.






          share|improve this answer



























            1












            1








            1







            Run the following to reclaim the directory (immediately and on subsequent boots):



            service='reclaim-postgresql'
            service_file="/etc/init.d/$service"

            echo "#!/bin/sh
            set -e

            ### BEGIN INIT INFO
            # Provides: $service
            # Required-Start: $postgres-xc
            # Required-Stop: $postgres-xc
            # Default-Start: 2 3 4 5
            # Default-Stop: 0 1 6
            # Short-Description: Reclaim /var/run/postgresql
            ### END INIT INFO

            chown -R $USER:$USER /var/run/postgresql"
            | sudo tee "$service_file"
            sudo chmod +x "$service_file"
            sudo update-rc.d "$service" defaults
            sudo service "$service" start


            Note that when running sudo apt-get upgrade to update postgres, you may need to temporarily sudo chown -R postgres:postgres /var/run/postgresql in order for the upgrade to succeed.






            share|improve this answer















            Run the following to reclaim the directory (immediately and on subsequent boots):



            service='reclaim-postgresql'
            service_file="/etc/init.d/$service"

            echo "#!/bin/sh
            set -e

            ### BEGIN INIT INFO
            # Provides: $service
            # Required-Start: $postgres-xc
            # Required-Stop: $postgres-xc
            # Default-Start: 2 3 4 5
            # Default-Stop: 0 1 6
            # Short-Description: Reclaim /var/run/postgresql
            ### END INIT INFO

            chown -R $USER:$USER /var/run/postgresql"
            | sudo tee "$service_file"
            sudo chmod +x "$service_file"
            sudo update-rc.d "$service" defaults
            sudo service "$service" start


            Note that when running sudo apt-get upgrade to update postgres, you may need to temporarily sudo chown -R postgres:postgres /var/run/postgresql in order for the upgrade to succeed.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 7 '16 at 23:07

























            answered Jun 6 '15 at 19:15









            JacksonJackson

            23629




            23629























                0














                Depending on your init system, add the chown/chmod command in the relevant init script for PostgreSQL such as /etc/init.d/postgresql.






                share|improve this answer



























                  0














                  Depending on your init system, add the chown/chmod command in the relevant init script for PostgreSQL such as /etc/init.d/postgresql.






                  share|improve this answer

























                    0












                    0








                    0







                    Depending on your init system, add the chown/chmod command in the relevant init script for PostgreSQL such as /etc/init.d/postgresql.






                    share|improve this answer













                    Depending on your init system, add the chown/chmod command in the relevant init script for PostgreSQL such as /etc/init.d/postgresql.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 4 '15 at 12:56









                    Josip RodinJosip Rodin

                    931412




                    931412





















                        0














                        Permissions for /var/run/postgresql are taken from /usr/lib/tmpfiles.d/postgresql.conf






                        share|improve this answer



























                          0














                          Permissions for /var/run/postgresql are taken from /usr/lib/tmpfiles.d/postgresql.conf






                          share|improve this answer

























                            0












                            0








                            0







                            Permissions for /var/run/postgresql are taken from /usr/lib/tmpfiles.d/postgresql.conf






                            share|improve this answer













                            Permissions for /var/run/postgresql are taken from /usr/lib/tmpfiles.d/postgresql.conf







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 23 at 7:30









                            Dmitry MedvedevDmitry Medvedev

                            11




                            11



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f206917%2fpermanently-change-permissions-of-var-run-postgresql%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

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay