PostgreSQL datasource URL

mac os xpostgresql

My first attempt to use PostgreSQL:

I have the elephant icon on the top right: running on port 5432.

I want to use LibreOffice as an interface:

  • Connect to an existing database: PostgreSQL
  • Datasource URL: ???

What should I put here? The database will be on the same computer where LibreOffice is running. Tried with localhost:5432 with no success.
By the way, I did not create the database, yet. Can I do it from LibreOffice?

Thank you.

Platform:
Mac OSX 10.7 – PostgreSQL 9.2.2 – LibreOffice 4.0

Best Answer

From ask.libreoffice, as linked on SuperUser

With the native postgreSQL connector the connection string is a little different. It is not a URL at all, but rather just a text string made up of propertyname=value segments, separated by a space.

The required fields (properties) are, database name and host (or hostaddr). If the postgreSQL database is using a non standard port (5432) then that must be included also.

So, if I want to connect to a database, using the default postgres configuration, named postgres on my local machine the simplest connection string would be: dbname=postgres host=localhost

Now let's say that there is an older postgres engine running using the standard 5432 port and I want to connect to a newer one using port 5433, and that I want to connect with my user name db_user, with a password of libreoffice and I don't want to type that password in each time I connect, then the connection string might look like:

dbname=postgres hostaddr=127.0.0.1 port=5433 user=db_user password=libreoffice

Note that I've used the hostaddr, instead of host here, bypassing any need to do a DNS lookup.

Finally, with the native connector all options in the connection string are accepted - you can find a full list of those here: PostgreSQL Docs Just remember that it is propertyName=value separated by spaces in Base.