• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • About
  • Projects
    • GStaticMap WP Plugin
  • Contact
  • Privacy Policy

Lorenz Blog

All About Web & Mobile Application Development

  • Featured Articles
  • Gadgets
    • Android
    • Blackberry
  • Programming
    • Android
    • PHP
    • Java Script
    • MySQL
    • Postgresql
    • Flex
    • Web
  • Software
    • Mac OS
    • Windows
    • Linux
  • Web
You are Here » Home >> Information Technology >> Programming >> Postgresql >> How to Use Postgresql pg_dump in Crontab Without Password

How to Use Postgresql pg_dump in Crontab Without Password

January 22, 2014 by Lorensius Londa 1 Comment

Postgresql pg_dump is a usefull tool to backup Postgresql database. By default, pg_dump will ask for a password of the user that runs the command from command line. It is pretty easy if we manually type it from command line. But if we want to use it in automatic regular backup using crontab, it can be a problem because we can not input the password.

For example, the pg_dump command in following cron job will not work:

5 0 * * * pg_dump -U username -Fc dbname > ~/backup/database/mydb_backup.gz

Fortunately, Postgresql has a Password File ‘.pgpass‘ feature that we can use to overcome this problem. Create a ~/.pgpass file in user’s home directory with the following format:

hostname:port:database:username:password
Ex: localhost:5432:mydatabase:lorenz:lorensxyz

Then don’t forget to change its’ permission to 0600 (chmod 0600 ~/.pgpass). pg_dump will use the password from .pgpass file and the cronjob will work successfully.

Facebooktwitterredditpinterestlinkedinmailby feather

Related posts:

  1. How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd
  2. How to Get Video Thumbnail and Duration Using Mplayer and PHP
  3. Installing TeamSpeak Server on FreeBSD
  4. How to Setup Gmail 2-Step Verification With Android

Filed Under: Database, Postgresql Tagged With: .pgpass, crontab, database backup, password, pg_dump, postgresql

About Lorensius Londa

Passionate web and mobile application developer. Co-founder of TRUSTUDIO, loves programming, Android, aviation, travelling, photography, coffee and gym mania.

Reader Interactions

Comments

  1. Dima Telezhnikov says

    April 22, 2015 at 2:17 am

    Thank you, it works! 🙂

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About Me

A husband, father of two, passionate software developer, diy lover and home baker who loves to learn new things. Read More…

  • Facebook
  • GitHub
  • Google+
  • Instagram
  • Twitter
  • YouTube

Featured Articles

How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Blue Bamboo P25 Printer Android Demo Application With Source Code

Simple JSON RPC Client for Android

How to Send Message to Google Cloud Messaging (GCM) Server Using JSON and PHP

Footer

Recent Comments

  • Aditya Dabas on About
  • Ayten Göksenin Barutçu on How to Make Android Map Scrollable Inside a ScrollView Layout
  • mang jojot on About
  • Hussain on How to Programmatically Scan or Discover Android Bluetooth Devices

Recent Posts

  • How to Fix Blank Screen on WordPress Add/Edit Post Page
  • How to Programmatically Restart the ESP32 Board
  • How to Get Hardware Info of ESP32
  • How to Setup MQTT Server Using Mosquitto and Libwebsocket on Freebsd

Latest Tweets

To protect our users from spam and other malicious activity, this account is temporarily locked. Please log in to https://twitter.com to unlock your account.

Copyright © 2023 · Magazine Pro on Genesis Framework · WordPress · Log in