prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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.
  
  </issue>
  <code>
  [start of frappe/database/postgres/setup_db.py]
  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 of frappe/database/postgres/setup_db.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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)
  
verification_info: {"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"}]}