Rails Whenever rake aborted! PG::ConnectionBad: fe_sendauth: no password supplied












0















I am using the Whenever gem for Rails to run a rake task checking the Postgres database for updates to entries. Running the rake file while SSH into the server works fine but with the cron job it does not run with the error message.



rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied



My setup is as follows:



database.yml



default: &default
adapter: postgresql
host: localhost
pool: 5
encoding: utf8
timeout: 5000
username: username
password: password

development:
<<: *default
database: development
password: password

test:
<<: *default
database: test

production:
<<: *default
database: production
password: password


script.rake



namespace :user do
desc "TODO"
task update_subscription: :environment do
puts "--- Starting user subscription check at #{DateTime.now} ---"
User.find_each do | user |
if user.refresh_date.past?
user.refresh_date = Date.today + 1.month
puts "User #{user.id} subscription updated"
end
end
end
end


schedule.rb



every 1.day, :at => '00:01 am' do
rake "user:update_subscription"
end


crontab -l



1 0 * * *  /bin/bash -l -c 'cd /home/app/app && RAILS_ENV=production bundle exec rake user:update_subscription --silent >> log/cron_log.log 2>&1'


pg_hba.conf



local   all             postgres                                peer

# TYPE DATABASE USER ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5


output in log file



--- Starting user subscription check at 2018-11-23T10:20:05+00:00 ---
rake aborted!
PG::ConnectionBad: fe_sendauth: no password supplied
/home/app/app/lib/tasks/script.rake:5:in `block (2
levels) in <top (required)>'
/home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `load'
/home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `<main>'
Tasks: TOP => user:update_subscription
(See full trace by running task with --trace)


If I change md5 and peer to trust in pg_hba.conf everything will work but as far as I know this is not good for security in a production environment.










share|improve this question



























    0















    I am using the Whenever gem for Rails to run a rake task checking the Postgres database for updates to entries. Running the rake file while SSH into the server works fine but with the cron job it does not run with the error message.



    rake aborted!
    PG::ConnectionBad: fe_sendauth: no password supplied



    My setup is as follows:



    database.yml



    default: &default
    adapter: postgresql
    host: localhost
    pool: 5
    encoding: utf8
    timeout: 5000
    username: username
    password: password

    development:
    <<: *default
    database: development
    password: password

    test:
    <<: *default
    database: test

    production:
    <<: *default
    database: production
    password: password


    script.rake



    namespace :user do
    desc "TODO"
    task update_subscription: :environment do
    puts "--- Starting user subscription check at #{DateTime.now} ---"
    User.find_each do | user |
    if user.refresh_date.past?
    user.refresh_date = Date.today + 1.month
    puts "User #{user.id} subscription updated"
    end
    end
    end
    end


    schedule.rb



    every 1.day, :at => '00:01 am' do
    rake "user:update_subscription"
    end


    crontab -l



    1 0 * * *  /bin/bash -l -c 'cd /home/app/app && RAILS_ENV=production bundle exec rake user:update_subscription --silent >> log/cron_log.log 2>&1'


    pg_hba.conf



    local   all             postgres                                peer

    # TYPE DATABASE USER ADDRESS METHOD

    # "local" is for Unix domain socket connections only
    local all all peer
    # IPv4 local connections:
    host all all 127.0.0.1/32 md5
    # IPv6 local connections:
    host all all ::1/128 md5
    # Allow replication connections from localhost, by a user with the
    # replication privilege.
    #local replication postgres peer
    #host replication postgres 127.0.0.1/32 md5
    #host replication postgres ::1/128 md5


    output in log file



    --- Starting user subscription check at 2018-11-23T10:20:05+00:00 ---
    rake aborted!
    PG::ConnectionBad: fe_sendauth: no password supplied
    /home/app/app/lib/tasks/script.rake:5:in `block (2
    levels) in <top (required)>'
    /home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `load'
    /home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `<main>'
    Tasks: TOP => user:update_subscription
    (See full trace by running task with --trace)


    If I change md5 and peer to trust in pg_hba.conf everything will work but as far as I know this is not good for security in a production environment.










    share|improve this question

























      0












      0








      0








      I am using the Whenever gem for Rails to run a rake task checking the Postgres database for updates to entries. Running the rake file while SSH into the server works fine but with the cron job it does not run with the error message.



      rake aborted!
      PG::ConnectionBad: fe_sendauth: no password supplied



      My setup is as follows:



      database.yml



      default: &default
      adapter: postgresql
      host: localhost
      pool: 5
      encoding: utf8
      timeout: 5000
      username: username
      password: password

      development:
      <<: *default
      database: development
      password: password

      test:
      <<: *default
      database: test

      production:
      <<: *default
      database: production
      password: password


      script.rake



      namespace :user do
      desc "TODO"
      task update_subscription: :environment do
      puts "--- Starting user subscription check at #{DateTime.now} ---"
      User.find_each do | user |
      if user.refresh_date.past?
      user.refresh_date = Date.today + 1.month
      puts "User #{user.id} subscription updated"
      end
      end
      end
      end


      schedule.rb



      every 1.day, :at => '00:01 am' do
      rake "user:update_subscription"
      end


      crontab -l



      1 0 * * *  /bin/bash -l -c 'cd /home/app/app && RAILS_ENV=production bundle exec rake user:update_subscription --silent >> log/cron_log.log 2>&1'


      pg_hba.conf



      local   all             postgres                                peer

      # TYPE DATABASE USER ADDRESS METHOD

      # "local" is for Unix domain socket connections only
      local all all peer
      # IPv4 local connections:
      host all all 127.0.0.1/32 md5
      # IPv6 local connections:
      host all all ::1/128 md5
      # Allow replication connections from localhost, by a user with the
      # replication privilege.
      #local replication postgres peer
      #host replication postgres 127.0.0.1/32 md5
      #host replication postgres ::1/128 md5


      output in log file



      --- Starting user subscription check at 2018-11-23T10:20:05+00:00 ---
      rake aborted!
      PG::ConnectionBad: fe_sendauth: no password supplied
      /home/app/app/lib/tasks/script.rake:5:in `block (2
      levels) in <top (required)>'
      /home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `load'
      /home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `<main>'
      Tasks: TOP => user:update_subscription
      (See full trace by running task with --trace)


      If I change md5 and peer to trust in pg_hba.conf everything will work but as far as I know this is not good for security in a production environment.










      share|improve this question














      I am using the Whenever gem for Rails to run a rake task checking the Postgres database for updates to entries. Running the rake file while SSH into the server works fine but with the cron job it does not run with the error message.



      rake aborted!
      PG::ConnectionBad: fe_sendauth: no password supplied



      My setup is as follows:



      database.yml



      default: &default
      adapter: postgresql
      host: localhost
      pool: 5
      encoding: utf8
      timeout: 5000
      username: username
      password: password

      development:
      <<: *default
      database: development
      password: password

      test:
      <<: *default
      database: test

      production:
      <<: *default
      database: production
      password: password


      script.rake



      namespace :user do
      desc "TODO"
      task update_subscription: :environment do
      puts "--- Starting user subscription check at #{DateTime.now} ---"
      User.find_each do | user |
      if user.refresh_date.past?
      user.refresh_date = Date.today + 1.month
      puts "User #{user.id} subscription updated"
      end
      end
      end
      end


      schedule.rb



      every 1.day, :at => '00:01 am' do
      rake "user:update_subscription"
      end


      crontab -l



      1 0 * * *  /bin/bash -l -c 'cd /home/app/app && RAILS_ENV=production bundle exec rake user:update_subscription --silent >> log/cron_log.log 2>&1'


      pg_hba.conf



      local   all             postgres                                peer

      # TYPE DATABASE USER ADDRESS METHOD

      # "local" is for Unix domain socket connections only
      local all all peer
      # IPv4 local connections:
      host all all 127.0.0.1/32 md5
      # IPv6 local connections:
      host all all ::1/128 md5
      # Allow replication connections from localhost, by a user with the
      # replication privilege.
      #local replication postgres peer
      #host replication postgres 127.0.0.1/32 md5
      #host replication postgres ::1/128 md5


      output in log file



      --- Starting user subscription check at 2018-11-23T10:20:05+00:00 ---
      rake aborted!
      PG::ConnectionBad: fe_sendauth: no password supplied
      /home/app/app/lib/tasks/script.rake:5:in `block (2
      levels) in <top (required)>'
      /home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `load'
      /home/app/.rbenv/versions/2.3.8/bin/bundle:22:in `<main>'
      Tasks: TOP => user:update_subscription
      (See full trace by running task with --trace)


      If I change md5 and peer to trust in pg_hba.conf everything will work but as far as I know this is not good for security in a production environment.







      ruby-on-rails postgresql cron psql whenever






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 10:36









      JackFurbyJackFurby

      113




      113
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Go to database.yml file, replace:



          host: localhost with host: ' '



          or check once this links :



          PG::ConnectionBad: fe_sendauth: no password supplied



          Rails + Postgres fe_sendauth: no password supplied



          Happy Coding ..!!!






          share|improve this answer
























          • That causes a different error rake aborted! PG::ConnectionBad: FATAL: Peer authentication failed for user "username"

            – JackFurby
            Nov 23 '18 at 11:11













          • From what I can find the fix for this error is host: localhost. It might be worth noting that the database is on the same server.

            – JackFurby
            Nov 23 '18 at 11:54



















          0














          After a lot more research I think I have found out why I was getting this problem. Cron jobs have limited environmental variables from the operating system. This meant the username, password, unix user etc. where not available and thus the error fe_sendauth: no password supplied was returned. Unfortunately I could not find a solution to this that worked in my situation but I changed from using Whenever to Crono which works great on just about the same code.



          If anyone wants to suggest something that may work for the original question please be my guest. Where possible I will try them out incase one works.






          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',
            autoActivateHeartbeat: false,
            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%2f53445050%2frails-whenever-rake-aborted-pgconnectionbad-fe-sendauth-no-password-supplie%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Go to database.yml file, replace:



            host: localhost with host: ' '



            or check once this links :



            PG::ConnectionBad: fe_sendauth: no password supplied



            Rails + Postgres fe_sendauth: no password supplied



            Happy Coding ..!!!






            share|improve this answer
























            • That causes a different error rake aborted! PG::ConnectionBad: FATAL: Peer authentication failed for user "username"

              – JackFurby
              Nov 23 '18 at 11:11













            • From what I can find the fix for this error is host: localhost. It might be worth noting that the database is on the same server.

              – JackFurby
              Nov 23 '18 at 11:54
















            0














            Go to database.yml file, replace:



            host: localhost with host: ' '



            or check once this links :



            PG::ConnectionBad: fe_sendauth: no password supplied



            Rails + Postgres fe_sendauth: no password supplied



            Happy Coding ..!!!






            share|improve this answer
























            • That causes a different error rake aborted! PG::ConnectionBad: FATAL: Peer authentication failed for user "username"

              – JackFurby
              Nov 23 '18 at 11:11













            • From what I can find the fix for this error is host: localhost. It might be worth noting that the database is on the same server.

              – JackFurby
              Nov 23 '18 at 11:54














            0












            0








            0







            Go to database.yml file, replace:



            host: localhost with host: ' '



            or check once this links :



            PG::ConnectionBad: fe_sendauth: no password supplied



            Rails + Postgres fe_sendauth: no password supplied



            Happy Coding ..!!!






            share|improve this answer













            Go to database.yml file, replace:



            host: localhost with host: ' '



            or check once this links :



            PG::ConnectionBad: fe_sendauth: no password supplied



            Rails + Postgres fe_sendauth: no password supplied



            Happy Coding ..!!!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 10:54









            tshrtshr

            76




            76













            • That causes a different error rake aborted! PG::ConnectionBad: FATAL: Peer authentication failed for user "username"

              – JackFurby
              Nov 23 '18 at 11:11













            • From what I can find the fix for this error is host: localhost. It might be worth noting that the database is on the same server.

              – JackFurby
              Nov 23 '18 at 11:54



















            • That causes a different error rake aborted! PG::ConnectionBad: FATAL: Peer authentication failed for user "username"

              – JackFurby
              Nov 23 '18 at 11:11













            • From what I can find the fix for this error is host: localhost. It might be worth noting that the database is on the same server.

              – JackFurby
              Nov 23 '18 at 11:54

















            That causes a different error rake aborted! PG::ConnectionBad: FATAL: Peer authentication failed for user "username"

            – JackFurby
            Nov 23 '18 at 11:11







            That causes a different error rake aborted! PG::ConnectionBad: FATAL: Peer authentication failed for user "username"

            – JackFurby
            Nov 23 '18 at 11:11















            From what I can find the fix for this error is host: localhost. It might be worth noting that the database is on the same server.

            – JackFurby
            Nov 23 '18 at 11:54





            From what I can find the fix for this error is host: localhost. It might be worth noting that the database is on the same server.

            – JackFurby
            Nov 23 '18 at 11:54













            0














            After a lot more research I think I have found out why I was getting this problem. Cron jobs have limited environmental variables from the operating system. This meant the username, password, unix user etc. where not available and thus the error fe_sendauth: no password supplied was returned. Unfortunately I could not find a solution to this that worked in my situation but I changed from using Whenever to Crono which works great on just about the same code.



            If anyone wants to suggest something that may work for the original question please be my guest. Where possible I will try them out incase one works.






            share|improve this answer




























              0














              After a lot more research I think I have found out why I was getting this problem. Cron jobs have limited environmental variables from the operating system. This meant the username, password, unix user etc. where not available and thus the error fe_sendauth: no password supplied was returned. Unfortunately I could not find a solution to this that worked in my situation but I changed from using Whenever to Crono which works great on just about the same code.



              If anyone wants to suggest something that may work for the original question please be my guest. Where possible I will try them out incase one works.






              share|improve this answer


























                0












                0








                0







                After a lot more research I think I have found out why I was getting this problem. Cron jobs have limited environmental variables from the operating system. This meant the username, password, unix user etc. where not available and thus the error fe_sendauth: no password supplied was returned. Unfortunately I could not find a solution to this that worked in my situation but I changed from using Whenever to Crono which works great on just about the same code.



                If anyone wants to suggest something that may work for the original question please be my guest. Where possible I will try them out incase one works.






                share|improve this answer













                After a lot more research I think I have found out why I was getting this problem. Cron jobs have limited environmental variables from the operating system. This meant the username, password, unix user etc. where not available and thus the error fe_sendauth: no password supplied was returned. Unfortunately I could not find a solution to this that worked in my situation but I changed from using Whenever to Crono which works great on just about the same code.



                If anyone wants to suggest something that may work for the original question please be my guest. Where possible I will try them out incase one works.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 27 '18 at 17:12









                JackFurbyJackFurby

                113




                113






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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%2fstackoverflow.com%2fquestions%2f53445050%2frails-whenever-rake-aborted-pgconnectionbad-fe-sendauth-no-password-supplie%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

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    RAC Tourist Trophy