0

I am currently working on an android application that saves data to a DB (My requirement is PostgreSQL and not SQLite DB). But I am unable to try saving records in PostgreSQL from my android application. Why i need PostgreSQL is that I need to access these DB records from another Spring MVC application for retrieving the saved records.

I read many blogs about port forwarding

Postgresql server remote connection

https://stackoverflow.com/questions/tagged/portforwarding?page=2&sort=newest

Unable to connect PostgreSQL to remote database using pgAdmin

and tried modifying the pg_hba.conf + postgresql.conf file based on the above blogs. After modifying these files the postgreSQL isn't loading as it says it couldn't find the pg_hba.conf file even though it is present. When i reverted back to original config then it started working but port forwarding settings isn't working.Not Sure whether port forwarding will solve this issue in my requirement. Any advise / alternate solution/ suggestion would really help me in proceeding further.

Community
  • 1
  • 1
SAMBA
  • 503
  • 2
  • 8
  • 15
  • 1
    I myself solved this issue by removing the '#' mark before this line hba_file = 'ConfigDir/pg_hba.conf' in the postgresql.conf file and added one line " host all all 0.0.0.0/0 md5" to the pg_hba.conf file. It worked perfectly. Now am able to run SELECT Query from my android application by connecting to a remote postgresql server. It works perfectly. Question is closed with above answer. – SAMBA Nov 10 '13 at 07:50
  • Be wary of security: that means you're allowing anybody in as any user. – Denis de Bernardy Nov 10 '13 at 12:49
  • Note that there is no port forwarding here. The line in `pg_hba.conf` just tells to accept all connections from any address. This is not the default because it's unusual to do that with a db server. Generally the connected app talks to a web service that talks to the database. – Daniel Vérité Nov 11 '13 at 14:37

1 Answers1

1

Basically port forwarding is pretty standard, but you do have to deal with the pg_hba.conf. As you found if this is a mobile application you will probably want to set it up to be accessible from anywhere. However, keep in mind that this poses some security risk. My recommendation, if you can, is to require SSL and to authenticate client-side certificates. You may find this question of interest.

Note you can do client-side cert authentication if you like with PostgreSQL which could be really handy in your case.

Community
  • 1
  • 1
Chris Travers
  • 25,424
  • 6
  • 65
  • 182