[OSM-dev] osm2pgsql password support documentation

Sven Geggus lists at fuchsschwanzdomain.de
Tue May 25 15:01:26 BST 2010

Jukka Rahkonen <jukka.rahkonen at latuviitta.fi> wrote:

> Right, username can be given after -U parameter and -W can be used to make
> osm2pgsql to ask for the password.  It is not possible to give the
> password from command line as -W my_password, it makes osm2pgsql to behave
> oddly. If I remember right it is trying to open an OSM file named
> "my_password" and stops.

Well osm2pgsql sourcecode might be arguably ugly, but it is not unreadable
after all :)

-W Option does _not_ allow for additional parameters at all thus something
like -W my_password is almost certainly interpreted as the mandatory

case 'W': pass_prompt=1; break

if (pass_prompt)
	password = simple_prompt("Password:", 100, 0);

The reason for Unix tools to not allow passwords to be given on the
commandline ist that this way anybody on the machine could read the password
in ps, top and the like. A common way to assign a passwort is by means of an
environment Variable.

If you want to have this the following patch could be applied:

Index: osm2pgsql.c
--- osm2pgsql.c	(Revision 21445)
+++ osm2pgsql.c	(Arbeitskopie)
@@ -753,6 +753,10 @@
     if (pass_prompt)
         password = simple_prompt("Password:", 100, 0);
+    else {
+        password = getenv("PGPASS");
+    }	

Afterwords one can use something like this:

PGPASS=pass_of_luser ./osm2pgsql testdat.osm



It's easier for our software to compete with Linux when there's piracy than
when there's not. (Bill Gates)

/me is giggls at ircnet, http://sven.gegg.us/ on the Web

More information about the dev mailing list