banner



How To Connect To Postgres Database Windows

Connect to PostgreSQL Database on Linux, Windows

Connect to PostgreSQL from the command line

Running the PostgreSQL interactive terminal program, called psql, which allows you to interactively enter, edit, and execute SQL commands. At the time of installing postgres to your operating system, it creates an "initial DB" and starts the postgres server domain running. Typically initdb creates a tabular array named "postgres" owned by user "current logged in user name"

At the command line in your operating organization, blazon the following command.

Debian based systems like Ubuntu :
Connect/login as root -

[electronic mail protected]:~$ sudo -i -u postgres [e-mail protected]:~$ psql psql (9.3.5, server 9.3.half-dozen) Type "help" for help.        

Redhat based systems like Centos / Fedora :
Connect/login as root -

[electronic mail protected]:~$ su - postgres [email protected]:~$ psql psql (ix.3.6)   Type "assistance" for help.        

Windows :
In windows, current user doesn't matter

C:\Program Files\PostgreSQL\9.4\bin>psql -U postgres Password for user postgres: psql (9.4.1) Type "help" for help.  postgres=#        

After accessing a PostgreSQL database, yous can run SQL queries and more. Hither are some commonpsql commands

  • To view aid forpsql commands, type \?.
  • To view help for SQL commands, type \h.
  • To view information about the current database connection, type \conninfo.
  • To list the database'due south tables and their respective owners, type \dt.
  • To list all of the tables, views, and sequences in the database, blazon \z.
  • To exit thepsql program, type \q.

What is psql?

psql is a terminal-based forepart-terminate to PostgreSQL. It enables yous to blazon in queries interactively, sent them to PostgreSQL, and see the query results.

psql [option...] [dbname [username]]        
Option Description
-a
--echo-all
Print all nonempty input lines to standard output as they are read. This is equivalent to setting the variable Repeat to all.
-A
--no-marshal
Switches to unaligned output mode.
-c command
--command=command
Specifies that psql is to execute one control string, command, and and then leave. This is useful in shell scripts. Start-up files (psqlrc and ~/.psqlrc) are ignored with this pick.
-d dbname
--dbname=dbname
Secifies the name of the database to connect to. This is equivalent to specifying dbname as the first not-choice argument on the command line.
-east
--echo-queries
Copy all SQL commands sent to the server to standard output equally well. This is equivalent to setting the variable ECHO to queries.
-Due east
--echo-subconscious
Apply the file filename equally the source of commands instead of reading commands interactively. After the file is processed, psql terminates. This is in many ways equivalent to the meta-control \i.
-F separator
--field-separator=separator
Apply separator as the field separator for unaligned output. This is equivalent to \pset fieldsep or \f.
-h hostname
--host=hostname
Specifies the host proper name of the auto on which the server is running. If the value begins with a slash, it is used equally the directory for the Unix-domain socket.
-H
--html
Turn on HTML tabular output. This is equivalent to \pset format html or the \H command.
-50
--list
List all bachelor databases, then exit. Other non-connection options are ignored. This is similar to the meta-command \listing.
-L filename
--log-file=filename
Write all query output into file filename, in addition to the normal output destination.
-n
--no-readline
Practice not apply Readline for line editing and do not use the control history. This can be useful to plough off tab expansion when cutting and pasting.
-o filename
--output=filename
Put all query output into file filename. This is equivalent to the command \o.
-p port
--port=port
Specifies the TCP port or the local Unix-domain socket file extension on which the server is listening for connections. Defaults to the value of the PGPORT environment variable or, if not gear up, to the port specified at compile time, usually 5432.
-P consignment
--pset=assignment
Specifies printing options, in the style of \pset. Notation that here you have to separate proper noun and value with an equal sign instead of space. For example, to fix the output format to LaTeX, you could write -P format=latex.
-q
--tranquillity
Specifies that psql should do its work quietly. By default, information technology prints welcome messages and various informational output. If this option is used, none of this happens. This is useful with the -c choice. This is equivalent to setting the variable Tranquillity to on.
-R separator
--record-separator=separator
Use separator equally the record separator for unaligned output.
-S
--single-line
Runs in single-line mode where a newline terminates an SQL command, as a semicolon does.
-t
--tuples-only
Turnoff printing of column names and upshot row count footers, etc.
-T table_options
--table-attr=table_options
Specifies options to be placed within the HTML tabular array tag. Encounter \pset for details.
-U username
--username=username
Connect to the database as the user username instead of the default. (You must accept permission to do so, of class.)
-five assignment
--set=assignment
--variable=assignment
Perform a variable consignment, similar the \gear up meta-command. Note that you must split name and value if any, by an equal sign on the control line.
-V
--version
Print the psql version and exit.
-w
--no-password
Never issue a password prompt. If the server requires password hallmark and a password is non bachelor by other means such every bit a .pgpass file, the connection endeavour will fail. This option can be useful in batch jobs and scripts where no user is nowadays to enter a password.
-W
--password
Force psql to prompt for a password before connecting to a database.
-x
--expanded
Plough on the expanded table formatting mode.
-10,
--no-psqlrc
Do not read the commencement-upwards file.
-z
--field-separator-zero
Set the field separator for unaligned output to a zero byte.
-0
--record-separator-nix
Set the record separator for unaligned output to a zero byte. This is useful for interfacing, for case, with xargs -0.
-one
--single-transaction
When psql executes a script with the -f pick, adding this option wraps BEGIN/COMMIT around the script to execute it as a unmarried transaction. This ensures that either all the commands consummate successfully, or no changes are practical.
-?
--assist
Show aid about psql command line arguments and go out.

Connect to PostgreSQL database using pgAdmin GUI application

Yous can besides connect to PostgreSQL database using pgAdmin GUI awarding. Connect to the database at localhost:5432 using the user name postgres and the password supplied.

postgresql pgadminIII

Clicking on pgAdmin III following screen will come:

postgresql pgadminIII part2

Now, double click on PostgreSQL 9.4 under the "Servers Groups". pgAdmin will enquire yous for a password. Y'all have to supply the password for the postgres user for authentication.

postgresql-pgadminIII part3

Under the Database(due south) on this server section, find the desired database and execute SQL queries:

postgresql-pgadminIII Part 4

Previous: PostgreSQL Installation
Next: PostgreSQL Connector and APIs

Source: https://www.w3resource.com/PostgreSQL/connect-to-postgresql-database.php

Posted by: popetwild1986.blogspot.com

0 Response to "How To Connect To Postgres Database Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel