views:

63

answers:

2

I need to set up the following env variables such that I can a database program which use PostgreSQL

export PGDATA="/home/masi/postgres/var"
export PGPORT="12428"

I know that the problem may be solved by adding the files to .zshrc. However, I am not sure whether it is the right way to go.

How can you add env variables?

+2  A: 

Put this somewhere in the main page of your app :

import os
os.environ["PGDATA"] = "/home/masi/postgres/var"
os.environ["PGPORT"] = 12428

however, isn't there a better way to set that in the framework you use?

OneOfOne
I do not know. I started PostgreSQL databases for the first time, and it just says that add these to your environmental variables.
Masi
+3  A: 

You only need to set the PGDATA variable in the script that starts the server. The client only cares about the port.

You do have to set the port value if you must run it on a non-standard port. I assume you have a good reason to not just run it on the default port? If you do run it on the default port (5432), it will just work without any parameters for it at all.

If you are running it on a different port, you should make two changes:

  • In postgresql.conf, set the port= value to the new port you want, and restart the database server.
  • In your settings.py in django, set the DATABASE_PORT value to the new port you want.

You should definitely not need to use environment variables for simple configuration options like these - avoiding them will make your life easier.

Magnus Hagander