Postgrest: Running postgrest in production mode

Created on 7 Feb 2017  路  12Comments  路  Source: PostgREST/postgrest

According to this doc I have made changes in my nginx conf file. Now I want to run my postgrest app, and I can do that by running ./postgrest postgres://postgres@localhost/catarse_development -a anonymous --jwt-secret gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C -s 1 -p 3004 . When the ssh session is closed, the server will also stop itself. How to keep the postgrest server running in production?

question

All 12 comments

There is a note here about keeping the server from stopping, let me know if it helps - http://postgrest.com/en/v0.4/admin.html#running-the-server

Also the way you're passing command line arguments looks like you're using version 0.3.x, have you looked into v0.4 yet? It has a lot of improvements.

@begriffs yes I am using v0.3.x :) . For now, I will not be able to use the latest release until I test everything out so I will be sticking with the old release.

Is the doc same for the v0.3.x as well? I have made changes to my nginx conf file and will that be valid for the old release?

And about running postgrest in production mode. After I ssh into my server do I run this ./postgrest postgres://postgres@localhost/catarse_development -a anonymous --jwt-secret gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C -s 1 -p 3004 </dev/null >/var/log/postgrest.log 2>&1 & and it will run in the background?

@begriffs I have used some arcane password for my database like $%$&*09 (example pass) and after I run ./postgrest postgres://postgres@localhost/catarse_development -a anonymous --jwt-secret gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C -s 1 -p 3004 I get *09@localhost/jvn_production: No such file or directory

You'll probably want to single-quote the connection string to prevent the shell from interpreting the weird characters. Like ./postgrest 'postgres://...etcetc' -a anonymous ...etc.

One benefit of the 0.4 version is that these strings are in a config file and do not need to be quoted, but quoting will work fine for you.

@begriffs I am lost. In the dev env, I was able to run like this ./postgrest postgres://postgres@localhost/catarse_development -a anonymous --jwt-secret gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C -s 1 -p 3004

now in the prod env , if I run it like this ./postgrest postgres://postgres@localhost/catarse_prod -a anonymous --jwt-secret gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C -s 1 -p 3004 I get

Listening on port 3004
postgrest: {"details":"fe_sendauth: no password supplied\n","message":"Can't connect to the database"}

so I again tried running this code

 ./postgrest "postgres://postgres:$u$h@&Tb123456789.0&@localhost/catarse_prod" -a anonymous --jwt-secret gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C -s 1 -p 3004

in prod env and got
postgrest: {"details":"could not translate host name \"&Tb123456789.0&@localhost\" to address: Name or service not known\n","message":"Can't connect to the database"} .

@begriffs I downloaded the latest release and ran it but my application breaks when using the latest release so I will be using the old release

The special characters in the password are confusing postgresql. For instance the @ usually goes between password and hostname, and you have two of them. The solution is to percent encode the password as suggested in http://stackoverflow.com/a/23361849

(Also the unix shell thinks $ is the beginning of a variable name because you are using double quotes rather than single quotes around the string.)

@begriffs Thanks a ton mate.

No problem. Also if you'd rather you could use the keyword/value style connection string rather than the a connection URI style - https://www.postgresql.org/docs/9.6/static/libpq-connect.html#LIBPQ-CONNSTRING

./ postgrest 'host=localhost port=5432 dbname=mydb' ...

Either style works, it's up to you.

thanks man, you are very helpful

@begriffs now my postgrest is running, however, it is not accepting any connections. I ran my postgrest like this

./postgrest 'postgres://test:%24u%24h%40%26Tb129.0@localhost:5432/test_production' -a anonymous --jwt-secret gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C -s 1 -p 3004

I ran netstat -na and found this

Proto Recv-Q  Send-Q     Local Address           Foreign Address         State
tcp        0           0              0.0.0.0:3004                     0.0.0.0:*                   LISTEN 

I had previously made changes to my nginx conf file by looking in this doc.

can u also tell me how I can run postgrest in the background?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kishyr picture kishyr  路  3Comments

ACPK picture ACPK  路  5Comments

msalvadores picture msalvadores  路  4Comments

priyank-purohit picture priyank-purohit  路  3Comments

ppKrauss picture ppKrauss  路  3Comments