2

I'm developing a python script that uses shp2sql via subprocess.call().

The string I'm using works fine on Linux Mint:

shp2pgsql -s 4326 ../data/download.shp ccd_hoods_new | psql -h hostname -d databasename -U username -P password -q

However, when I run the script on CentOS, I'm prompted for a password, which presents a new problem when deploying and automating via CRON.

The only documentation I can find is this cheatsheet, which confirms that I'm doing things correctly.

But why on the CentOS machine would it not be recognizing the -P flag?

Both servers are running the same script that points to the same host running PostgreSQL 9.6 and PostGIS 2.4.

1
  • There is a space between - and P. If not a typo, try removing it
    – JGH
    Commented Oct 10, 2017 at 20:40

1 Answer 1

4

The -P argument to psql is not used to supply a password; see the documentation at this link.

You can supply a password to psql using one of three methods:

  1. Enter the password at a prompt
  2. Enter the password in your ~/.pgpass file
  3. Set the PGPASSWORD environment variable

Maybe your Mint system has the password defined using #2 or #3? If not, perhaps the server has disabled authentication when connecting from certain IP addresses.

EDIT by @DPSSpatial

  1. works by constructing the following command:

    shp2pgsql -s 4326 ../data/download.shp ccd_hoods_new | PGPASSWORD=password psql -h hostname -d database -U username -q
    

I found this syntax from this post: https://stackoverflow.com/a/24953448/1704448

1
  • Hope you don't mind the edit I made, but that got me on the right track... thanks again! Commented Oct 11, 2017 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.