2

The ogr2ogr command in this question How to Import ESRI Geodatabase format .gdb into PostGIS was missing the host and port arguments, or so I thought.

My answer included something like this

ogr2ogr -f "PostgreSQL" PG:"host=localhost port=5432 dbname=NY user=postgres" NY.gdb 

I know my command works (even if it was down-voted) but I wonder if there are cases when the host and port arguments are not required.


So it's possible for my server to be running on the default port, I see. So, how or why would i set up the server to run on the default port? Thanks.
Martin F
  • 8,948
  • 36
  • 58

1 Answers1

5

No, according to the docs, the host name and port aren't required in all cases. The simple form is PG:dbname=databasename.

When the host name and port are omitted, the connection is made to localhost on the default port. You should only have to specify the host and port if you are connecting to a different machine or to a server running on a different port.

edit:
You might run PostgreSQL on a different port if something is already using the default port. It might also be considered more secure to run it on an arbitrary port since you'd have to know both the host and the port in order to connect (in addition to a user and pass).

A real world example of this: I wanted to test ArcGIS 10.1 with PostgreSQL, utilizing both PostGIS and ESRI ST_Geometry types. In this scenario, I was restricted to PostGIS 1.5 32bit, but I could use 64bit for ST_Geometry. I could have used the same 32bit server for both, but I chose to have two different servers to test out 32bit vs. 64bit as well. So my 32bit server ran on port 5432 and the 64bit server on 5433 on the same machine.

Evil Genius
  • 6,289
  • 2
  • 27
  • 40
  • 1
    @martinf I've added some detail for your additional question. If you still want more detail, then you'll probably want to create a new question (or better yet, search for an existing one first). – Evil Genius Feb 18 '14 at 18:12
  • Actually, my 2nd Q was why run the server on the default port. I already have a setup virtually identical to the one you describe. Since i've always followed the advice of using 5432, etc, it's not really a problem i need solving. So leave it to me to ponder, if you like ;-) I was just wondering about that initial situation/question -- the case when the default port is used. I'm guessing the only advantage to that is that it saves a bit of typing. Cheers. – Martin F Feb 18 '14 at 22:08
  • @martinf Oh, you are right, I misread that. In that case, I would say it's for convenience. – Evil Genius Feb 18 '14 at 23:41
  • Why sir/maam, you are an evil genius. – Martin F Feb 19 '14 at 01:10