We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Hard coded localhost for pgsql setup
The postgresql setup is using `localhost` instead of the `db_host` from the site configuration:
https://github.com/frappe/frappe/blob/17c43b4e1d2506e5b1498e52f3aa6c81277d67be/frappe/database/postgres/setup_db.py#L20

This makes it impossible to use Postgres on a remote host :/

I can try to provide a PR for that.
I do not guaranty I will have the time to test it but it's fairly simple.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `frappe/database/postgres/setup_db.py`
Content:
```
1 import frappe, subprocess, os
2 from six.moves import input
3 
4 def setup_database(force, source_sql, verbose):
5 	root_conn = get_root_connection()
6 	root_conn.commit()
7 	root_conn.sql("DROP DATABASE IF EXISTS `{0}`".format(frappe.conf.db_name))
8 	root_conn.sql("DROP USER IF EXISTS {0}".format(frappe.conf.db_name))
9 	root_conn.sql("CREATE DATABASE `{0}`".format(frappe.conf.db_name))
10 	root_conn.sql("CREATE user {0} password '{1}'".format(frappe.conf.db_name,
11 		frappe.conf.db_password))
12 	root_conn.sql("GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}".format(frappe.conf.db_name))
13 
14 	# we can't pass psql password in arguments in postgresql as mysql. So
15 	# set password connection parameter in environment variable
16 	subprocess_env = os.environ.copy()
17 	subprocess_env['PGPASSWORD'] = str(frappe.conf.db_password)
18 	# bootstrap db
19 	subprocess.check_output([
20 		'psql', frappe.conf.db_name, '-h', 'localhost', '-U',
21 		frappe.conf.db_name, '-f',
22 		os.path.join(os.path.dirname(__file__), 'framework_postgres.sql')
23 	], env=subprocess_env)
24 
25 	frappe.connect()
26 
27 def setup_help_database(help_db_name):
28 	root_conn = get_root_connection()
29 	root_conn.sql("DROP DATABASE IF EXISTS `{0}`".format(help_db_name))
30 	root_conn.sql("DROP USER IF EXISTS {0}".format(help_db_name))
31 	root_conn.sql("CREATE DATABASE `{0}`".format(help_db_name))
32 	root_conn.sql("CREATE user {0} password '{1}'".format(help_db_name, help_db_name))
33 	root_conn.sql("GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}".format(help_db_name))
34 
35 def get_root_connection(root_login=None, root_password=None):
36 	import getpass
37 	if not frappe.local.flags.root_connection:
38 		if not root_login:
39 			root_login = frappe.conf.get("root_login") or None
40 
41 		if not root_login:
42 			root_login = input("Enter postgres super user: ")
43 
44 		if not root_password:
45 			root_password = frappe.conf.get("root_password") or None
46 
47 		if not root_password:
48 			root_password = getpass.getpass("Postgres super user password: ")
49 
50 		frappe.local.flags.root_connection = frappe.database.get_db(user=root_login, password=root_password)
51 
52 	return frappe.local.flags.root_connection
53
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/frappe/database/postgres/setup_db.py b/frappe/database/postgres/setup_db.py
--- a/frappe/database/postgres/setup_db.py
+++ b/frappe/database/postgres/setup_db.py
@@ -17,7 +17,7 @@
 	subprocess_env['PGPASSWORD'] = str(frappe.conf.db_password)
 	# bootstrap db
 	subprocess.check_output([
-		'psql', frappe.conf.db_name, '-h', 'localhost', '-U',
+		'psql', frappe.conf.db_name, '-h', frappe.conf.db_host, '-U',
 		frappe.conf.db_name, '-f',
 		os.path.join(os.path.dirname(__file__), 'framework_postgres.sql')
 	], env=subprocess_env)

{"golden_diff": "diff --git a/frappe/database/postgres/setup_db.py b/frappe/database/postgres/setup_db.py\n--- a/frappe/database/postgres/setup_db.py\n+++ b/frappe/database/postgres/setup_db.py\n@@ -17,7 +17,7 @@\n \tsubprocess_env['PGPASSWORD'] = str(frappe.conf.db_password)\n \t# bootstrap db\n \tsubprocess.check_output([\n-\t\t'psql', frappe.conf.db_name, '-h', 'localhost', '-U',\n+\t\t'psql', frappe.conf.db_name, '-h', frappe.conf.db_host, '-U',\n \t\tfrappe.conf.db_name, '-f',\n \t\tos.path.join(os.path.dirname(__file__), 'framework_postgres.sql')\n \t], env=subprocess_env)\n", "issue": "Hard coded localhost for pgsql setup\nThe postgresql setup is using `localhost` instead of the `db_host` from the site configuration:\r\nhttps://github.com/frappe/frappe/blob/17c43b4e1d2506e5b1498e52f3aa6c81277d67be/frappe/database/postgres/setup_db.py#L20\r\n\r\nThis makes it impossible to use Postgres on a remote host :/\r\n\r\nI can try to provide a PR for that.\r\nI do not guaranty I will have the time to test it but it's fairly simple.\n", "before_files": [{"content": "import frappe, subprocess, os\nfrom six.moves import input\n\ndef setup_database(force, source_sql, verbose):\n\troot_conn = get_root_connection()\n\troot_conn.commit()\n\troot_conn.sql(\"DROP DATABASE IF EXISTS `{0}`\".format(frappe.conf.db_name))\n\troot_conn.sql(\"DROP USER IF EXISTS {0}\".format(frappe.conf.db_name))\n\troot_conn.sql(\"CREATE DATABASE `{0}`\".format(frappe.conf.db_name))\n\troot_conn.sql(\"CREATE user {0} password '{1}'\".format(frappe.conf.db_name,\n\t\tfrappe.conf.db_password))\n\troot_conn.sql(\"GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}\".format(frappe.conf.db_name))\n\n\t# we can't pass psql password in arguments in postgresql as mysql. So\n\t# set password connection parameter in environment variable\n\tsubprocess_env = os.environ.copy()\n\tsubprocess_env['PGPASSWORD'] = str(frappe.conf.db_password)\n\t# bootstrap db\n\tsubprocess.check_output([\n\t\t'psql', frappe.conf.db_name, '-h', 'localhost', '-U',\n\t\tfrappe.conf.db_name, '-f',\n\t\tos.path.join(os.path.dirname(__file__), 'framework_postgres.sql')\n\t], env=subprocess_env)\n\n\tfrappe.connect()\n\ndef setup_help_database(help_db_name):\n\troot_conn = get_root_connection()\n\troot_conn.sql(\"DROP DATABASE IF EXISTS `{0}`\".format(help_db_name))\n\troot_conn.sql(\"DROP USER IF EXISTS {0}\".format(help_db_name))\n\troot_conn.sql(\"CREATE DATABASE `{0}`\".format(help_db_name))\n\troot_conn.sql(\"CREATE user {0} password '{1}'\".format(help_db_name, help_db_name))\n\troot_conn.sql(\"GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}\".format(help_db_name))\n\ndef get_root_connection(root_login=None, root_password=None):\n\timport getpass\n\tif not frappe.local.flags.root_connection:\n\t\tif not root_login:\n\t\t\troot_login = frappe.conf.get(\"root_login\") or None\n\n\t\tif not root_login:\n\t\t\troot_login = input(\"Enter postgres super user: \")\n\n\t\tif not root_password:\n\t\t\troot_password = frappe.conf.get(\"root_password\") or None\n\n\t\tif not root_password:\n\t\t\troot_password = getpass.getpass(\"Postgres super user password: \")\n\n\t\tfrappe.local.flags.root_connection = frappe.database.get_db(user=root_login, password=root_password)\n\n\treturn frappe.local.flags.root_connection\n", "path": "frappe/database/postgres/setup_db.py"}], "after_files": [{"content": "import frappe, subprocess, os\nfrom six.moves import input\n\ndef setup_database(force, source_sql, verbose):\n\troot_conn = get_root_connection()\n\troot_conn.commit()\n\troot_conn.sql(\"DROP DATABASE IF EXISTS `{0}`\".format(frappe.conf.db_name))\n\troot_conn.sql(\"DROP USER IF EXISTS {0}\".format(frappe.conf.db_name))\n\troot_conn.sql(\"CREATE DATABASE `{0}`\".format(frappe.conf.db_name))\n\troot_conn.sql(\"CREATE user {0} password '{1}'\".format(frappe.conf.db_name,\n\t\tfrappe.conf.db_password))\n\troot_conn.sql(\"GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}\".format(frappe.conf.db_name))\n\n\t# we can't pass psql password in arguments in postgresql as mysql. So\n\t# set password connection parameter in environment variable\n\tsubprocess_env = os.environ.copy()\n\tsubprocess_env['PGPASSWORD'] = str(frappe.conf.db_password)\n\t# bootstrap db\n\tsubprocess.check_output([\n\t\t'psql', frappe.conf.db_name, '-h', frappe.conf.db_host, '-U',\n\t\tfrappe.conf.db_name, '-f',\n\t\tos.path.join(os.path.dirname(__file__), 'framework_postgres.sql')\n\t], env=subprocess_env)\n\n\tfrappe.connect()\n\ndef setup_help_database(help_db_name):\n\troot_conn = get_root_connection()\n\troot_conn.sql(\"DROP DATABASE IF EXISTS `{0}`\".format(help_db_name))\n\troot_conn.sql(\"DROP USER IF EXISTS {0}\".format(help_db_name))\n\troot_conn.sql(\"CREATE DATABASE `{0}`\".format(help_db_name))\n\troot_conn.sql(\"CREATE user {0} password '{1}'\".format(help_db_name, help_db_name))\n\troot_conn.sql(\"GRANT ALL PRIVILEGES ON DATABASE `{0}` TO {0}\".format(help_db_name))\n\ndef get_root_connection(root_login=None, root_password=None):\n\timport getpass\n\tif not frappe.local.flags.root_connection:\n\t\tif not root_login:\n\t\t\troot_login = frappe.conf.get(\"root_login\") or None\n\n\t\tif not root_login:\n\t\t\troot_login = input(\"Enter postgres super user: \")\n\n\t\tif not root_password:\n\t\t\troot_password = frappe.conf.get(\"root_password\") or None\n\n\t\tif not root_password:\n\t\t\troot_password = getpass.getpass(\"Postgres super user password: \")\n\n\t\tfrappe.local.flags.root_connection = frappe.database.get_db(user=root_login, password=root_password)\n\n\treturn frappe.local.flags.root_connection\n", "path": "frappe/database/postgres/setup_db.py"}]}