diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py index 4c9bd63546..3b5ddafaca 100644 --- a/django/db/backends/postgresql/client.py +++ b/django/db/backends/postgresql/client.py @@ -32,9 +32,9 @@ class DatabaseClient(BaseDatabaseClient): args += ["-h", host] if port: args += ["-p", str(port)] + args.extend(parameters) if dbname: args += [dbname] - args.extend(parameters) env = {} if passwd: diff --git a/tests/dbshell/test_postgresql.py b/tests/dbshell/test_postgresql.py index 02924d0bcc..53dedaca01 100644 --- a/tests/dbshell/test_postgresql.py +++ b/tests/dbshell/test_postgresql.py @@ -154,7 +154,7 @@ class PostgreSqlDbshellCommandTestCase(SimpleTestCase): def test_parameters(self): self.assertEqual( self.settings_to_cmd_args_env({"NAME": "dbname"}, ["--help"]), - (["psql", "dbname", "--help"], None), + (["psql", "--help", "dbname"], None), ) @skipUnless(connection.vendor == "postgresql", "Requires a PostgreSQL connection")