diff -up sos-3.0/sos/plugins/postgresql.py.orig sos-3.0/sos/plugins/postgresql.py --- sos-3.0/sos/plugins/postgresql.py.orig 2014-11-11 17:22:24.973592961 +0000 +++ sos-3.0/sos/plugins/postgresql.py 2014-11-11 17:29:02.374434446 +0000 @@ -13,23 +13,27 @@ class PostgreSQL(Plugin): tmp_dir = None + password_warn_text = " (password visible in process listings)" + option_list = [ ("pghome", 'PostgreSQL server home directory.', '', '/var/lib/pgsql'), ("username", 'username for pg_dump', '', 'postgres'), - ("password", 'password for pg_dump', '', ''), - ("dbname", 'database name to dump for pg_dump', '', ''), + ('password', 'password for pg_dump' + password_warn_text, '', ''), + ("dbname", 'database name to dump for pg_dump', '', '') ] def pg_dump(self): dest_file = os.path.join(self.tmp_dir, "sos_pgdump.tar") - old_env_pgpassword = os.environ.get("PGPASSWORD") - os.environ["PGPASSWORD"] = self.get_option("password") + # We're only modifying this for ourself and our children so there + # is no need to save and restore environment variables if the user + # decided to pass the password on the command line. + if self.get_option("password") is not None: + os.environ["PGPASSWORD"] = self.get_option("password") + (status, output, rtime) = self.call_ext_prog("pg_dump %s -U %s -w -f %s -F t" % (self.get_option("dbname"), self.get_option("username"), dest_file)) - if old_env_pgpassword is not None: - os.environ["PGPASSWORD"] = old_env_pgpassword if (status == 0): self.add_copy_spec(dest_file) else: @@ -37,7 +41,7 @@ class PostgreSQL(Plugin): def setup(self): if self.get_option("dbname"): - if self.get_option("password"): + if self.get_option("password") or "PGPASSWORD" in os.environ: self.tmp_dir = tempfile.mkdtemp() self.pg_dump() else: