PostgreSQL

  • We have highlighted your search term postgis for you. If you'd like to remove the search term, click here.

 

PostGIS quick start guide

How to start/stop the PostgreSQL server?

The Stacks include a graphical tool to manage the servers easily. You can find the "manager-windows.exe", "manager-osx" or "manager-linux" tool in your installation directory. Using this tool, you can Start, Stop or Restart the servers and check the log files. You can click on the icon to start it.

manager-servers.png

 

manager-osx.png

 

 

 

 

 

 

 

 

 


win_platform.png On Windows: You can also start the Manager tool from shortcuts: Start -> Program Files -> BitNami Stack -> Manager tool

 

If you prefer, you can use the "ctlscript.sh" utility from the command line. This script is in the installation directory.

mac_platform.png

On OS X: You can start the Manager tool from the installation directory or you can use the "ctlscript.sh" utility from a Terminal.

host:~ user$ cd /Applications/application-version
host:~ user$ ./ctlscript.sh start

linux_platform.png On Linux:

$ cd ~/applicaton-version
$ ./ctlscript.sh start

What is the default configuration?

PostgreSQL's grant tables are created during the BitNami Stack installation process. The grant tables define the initial PostgreSQL user accounts and their access privileges. The default configuration consists of: 

  • A privileged account with a username of 'postgres'. The initial password for this account is the same you specified in the setup wizard. For Virtual Appliances or AMIs the default password is "bitnami".

It is strongly recommended that you do not have empty passwords for any user accounts before using the server for any production work.

For security reasons, the PostgreSQL database does not let external connections by default. You only can connect from the local machine.

PostgreSQL socket

On Unix the PostgreSQL clients can connect to the server using an Unix socket file. In  a BitNami Stack the default socket file is created in /installdir/postgres/.s.PGSQL.5432. Usually when you use a postgresql client tool included in the stack you will not need to specify the socket for the connection.

How to connect to the PostgreSQL database?

You can connect to PostgreSQL database from the same computer where it is installed.

  1. Open the BitNami console
  2. Run the postgresql client:
$ psql -U postgres

You can also run the postgreSQL client directly "/installdir/postgresql/bin/psql". If you have installed phpPgAdmin component, you can manage the PostgreSQL database from a browser. You can find more info at phpPgAdmin.

How to connect to the PostgreSQL database from a different machine?

First of all, you have to open the PostGreSQL port in your machine. It is 5432 by default, but you can check it in installdir/bitnami/properties.ini file. To open this port, follow the instructions in our wiki:
http://wiki.bitnami.com/Virtual_Appliances_Quick_Start_Guide?highlight=ufw#How_to_configure_the_Firewall.3f
After that, you have to change the following config files to make your PostgreSQL available remotely. Allow remote access to postgresql database

$ vim installdir/postgresql/pg_hba.conf


Now append the following line.

host all all ip_address net_mask auth_method

where "ip_address" means your IP (can be a network IP). "net_mask" means network mask. "auth_method" means authentication method. There are few authentication methods. such as "password, trust, md5". You should use md5 to use encrypted password authentication.
eg:
host all all 192.168.1.1 255.255.255.0 md5

Allow TCP/IP communication

$ vim installdir/postgresql/postgresql.conf

In the "listen_addresses" option you have to change the default value, "localhost", to '*' (or an IP if you prefer).

After that, restart the postgresql database

 

installdir/ctlstript.sh restart

 

Now, you should be able to access to your PostgreSQL database from another machines.

How to change the PostgreSQL password?

These are the default credentials for the PostgreSQL database. 

  • username: postgres
  • password: bitnami (for BitNami AMIs), <application password> (for BitNami Cloud Hosting and Native Installers)

You can change the "postgres" user password from the command line:

$ psql -U postgres
postgres=# alter user postgres with password 'YOUR_NEW_PASSWORD';
postgresl=# \q

 

How to reset the PostgreSQL password?

If you don't remember your PostgreSQL database password, you can follow the steps below to reset it to a new value: (Assuming that the installation directory is /opt/bitnami)

Change the authentication method in the configuration file  /opt/bitnami/postgresql/data/pg_hba.conf from 'md5' to 'trust' and reload the configuration. You can do this with the commands below:

sudo sed -ibak 's/^\([^#]*\)md5/\1trust/g' /opt/bitnami/postgresql/data/pg_hba.conf
sudo -u postgres pg_ctl reload

You should be now able to connect to the PostgreSQL database and set the password to a new value:

psql -U postgres
postgres=# alter user postgres with password 'YOUR_NEW_PASSWORD';
postgresl=# \q

Finally, change back the authentication method top md5 and reload the old PostgreSQL configuration: 

sudo sed -i 's/^\([^#]*\)trust/\1md5/g' /opt/bitnami/postgresql/data/pg_hba.conf
sudo -u postgres pg_ctl reload

You should now be able to connect to PostgrSQL with the new password.

How to create a database backup?

If you are interested in a backup of only the database data, you can create a dump file using the “pgdump” tool.

$ /installdir/postgresql/bin/pg_dump -U postgres database_name > backup.sql

This operation could take some time depending on the data size.

How to restore a database backup?

Once you have the backup file, you can restore it.

$ psql -U postgres database_name < backup.sql

If you want to restore the database and the database schema does not exist, it is necessary to first follow the steps described below. As a side note, you can find the value for BITNAMI_USER_PASSWORD below in the application configuration file. This depends on the application and you can find this information in the application page itself.

$ psql -U postgres
drop database database_name;
create database database_name;
create user database_user;
alter role database_user with password 'BITNAMI_USER_PASSWORD';
grant all privileges on database database_name to database_user;
alter database database_name owner to database_user;
$ psql -U postgres database_name < backup.sql

Note that the steps previously described will only back up the state of your database. Other files that you should take into account when performing a backup are files that have been uploaded to the application. These files are stored in the application folder itslef so you can copy this folder to have a backup of your uploaded files.

How to install PostGIS in the PostgreSQL database on Windows?

Since BitNami WAPP Stack version 5.4.0-1 version, PostGIS is already included in the stack.

PostGIS adds support for geographic objects to the PostgreSQL object-relational database.These are the basic steps to install this extension in a BitNami WAPP Stack.

  1. Download and install the BitNami WAPPStack on your computer.
  2. Download PostGIS for Windows: http://postgis.refractions.net/download/windows/
      - PostGIS 1.5.3 release for PostgreSQL 9.1 download link: http://postgis.refractions.net/download/windows/pg91/postgis-pg91-setup-1.5.3-2.exe
    Note: The version of PostGIS must be compatible with the version of PostgreSQL installed with WAPPStack. At the moment of writing this artivle
  3. Specify the PostgreSQL installation directory, "C:\Program Files\BitNami WAPPStack\postgresql" by default.
  4. When prompted the password, enter the same that you specified during the BitNami WAPPStack installation
  5. Accept defaults enable enable the "shp2pgsql" loader in PgAdmin III.
  6. Verify the "postgis" database has been successfully created. You can check it using the phpPgAdmin application at http://127.0.0.1/phppgadmin. The default user is "postgres" and the password is the same that you set during the WAPPStack installation.

How to install PostGIS in the PostgreSQL database on Linux?

Since BitNami LAPP Stack version 5.4.0-1 version, PostGIS is already included in the stack so it is not necessary to install it manually.

PostGIS adds support for geographic objects to the PostgreSQL object-relational database.These are the basic steps to install this extension in a BitNami LAPP Stack Ubuntu Virtual Appliance or AMI. Notice that the versions could be different.

$ sudo apt-get update
$ sudo apt-get install build-essential libtool autoconf unzip wget 

Download and install the dependencies:

$ wget http://download.osgeo.org/geos/geos-3.3.2.tar.bz2
$ bunzip2 geos-3.3.2.tar.bz2
$ tar -xvf geos-3.3.2.tar
$ cd geos-3.3.2
$ ./configure
$ make 
$ sudo make install

This could take some time

$ wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
$ tar -xzvf proj-4.8.0.tar.gz
$ cd proj-4.8.0
$ ./configure
$ make
$ sudo make install

Now download and install the PostGIS.

$ wget http://postgis.refractions.net/download/postgis-1.5.3.tar.gz
$ tar -xzvf postgis-1.5.3.tar.gz
$ cd postgis-1.5.3
$ ./configure
$ make
$ sudo make install

You can find more info about how to configure the PostgreSQL database using PostGIS at http://postgis.refractions.net/docs/ch02.html

How to debug errors?

The main PostgreSQL log file is created at /installdir/postgresql/postgresql.log file.

Comments

You must login to post a comment.

Attach file

Attachments