- Connect to a PostgreSQL Data Source (SQL Server Import and Export Wizard)
- Get the PostgreSQL ODBC driver
- Install the ODBC driver with Stack Builder
- Or, download the latest ODBC driver
- Connect to PostgreSQL with the PostgreSQL ODBC driver (psqlODBC)
- Options to specify (PostgreSQL ODBC driver)
- Connection string format
- Enter the connection string
- Other data providers and more info
- Подключение к источнику данных PostgreSQL (мастер импорта и экспорта SQL Server) Connect to a PostgreSQL Data Source (SQL Server Import and Export Wizard)
- Получение драйвера ODBC для PostgreSQL Get the PostgreSQL ODBC driver
- Установка драйвера ODBC с помощью построителя стека Install the ODBC driver with Stack Builder
- Скачивание последней версии драйвера ODBC Or, download the latest ODBC driver
- Подключение к PostgreSQL с помощью драйвера ODBC для PostgreSQL (psqlODBC) Connect to PostgreSQL with the PostgreSQL ODBC driver (psqlODBC)
- Указываемые параметры (драйвер ODBC для PostgreSQL) Options to specify (PostgreSQL ODBC driver)
- Формат строки подключения Connection string format
- Ввод строки подключения Enter the connection string
- Другие поставщики данных и дополнительные сведения Other data providers and more info
- Connect to PostgreSQL Database on Linux, Windows
- Connect to PostgreSQL from the command line
Connect to a PostgreSQL Data Source (SQL Server Import and Export Wizard)
Applies to: SQL Server (all supported versions) SSIS Integration Runtime in Azure Data Factory
This topic shows you how to connect to a PostgreSQL data source from the Choose a Data Source or Choose a Destination page of the SQL Server Import and Export Wizard.
The detailed requirements and prerequisites for connecting to a PostgreSQL database are beyond the scope of this Microsoft article. This article assumes that you already have PostgreSQL client software installed and that you can already connect successfully to the target PostgreSQL database. For more info, consult your PostgreSQL database administrator or the PostgreSQL documentation.
Get the PostgreSQL ODBC driver
Install the ODBC driver with Stack Builder
Run Stack Builder to add the PostgreSQL ODBC driver (psqlODBC) to your installation of PostgreSQL.
Or, download the latest ODBC driver
Or, download the Windows installer for the latest version of the PostgreSQL ODBC driver (psqlODBC) directly from this FTP site — https://www.postgresql.org/ftp/odbc/versions/msi/. Extract the files from the .zip file and run the .msi file.
Connect to PostgreSQL with the PostgreSQL ODBC driver (psqlODBC)
ODBC drivers aren’t listed in the drop-down list of data sources. To connect with an ODBC driver, start by selecting the .NET Framework Data Provider for ODBC as the data source on the Choose a Data Source or Choose a Destination page. This provider acts as a wrapper around the ODBC driver.
Here’s the generic screen that you see immediately after selecting the .NET Framework Data Provider for ODBC.
Options to specify (PostgreSQL ODBC driver)
The connection options for this data provider and ODBC driver are the same whether PostgreSQL is your source or your destination. That is, the options you see are the same on both the Choose a Data Source and the Choose a Destination pages of the wizard.
To connect to PostgreSQL with the PostgreSQL ODBC driver, assemble a connection string that includes the following settings and their values. The format of a complete connection string immediately follows the list of settings.
Get help assembling a connection string that’s just right. Or, instead of providing a connection string, provide an existing DSN (data source name) or create a new one. For more info about these options, see Connect to an ODBC Data Source.
Driver
The name of the ODBC driver — either PostgreSQL ODBC Driver(UNICODE) or PostgreSQL ODBC Driver(ANSI).
Server
The name of the PostgreSQL server.
Port
The port to use to connect to the PostgreSQL server.
Database
The name of the PostgreSQL database.
Uid and Pwd
The Uid (user id) and Pwd (password) to connect.
Connection string format
Here’s the format of a typical connection string.
Enter the connection string
Enter the connection string in the ConnectionString field, or enter the DSN name in the Dsn field, on the Choose a Data Source or Choose a Destination page. After you enter the connection string, the wizard parses the string and displays the individual properties and their values in the list.
The following example uses this connection string.
Here’s the screen that you see after entering the connection string.
Other data providers and more info
For info about how to connect to PostgreSQL with a data provider that’s not listed here, see PostgreSQL connection strings. This third-party site also contains more info about the data providers and the connection parameters described on this page.
Подключение к источнику данных PostgreSQL (мастер импорта и экспорта SQL Server) Connect to a PostgreSQL Data Source (SQL Server Import and Export Wizard)
Применимо к: Applies to: SQL Server SQL Server (все поддерживаемые версии) SQL Server SQL Server (all supported versions) Azure-SSIS Integration Runtime в Фабрике данных Azure SSIS Integration Runtime in Azure Data Factory Azure-SSIS Integration Runtime в Фабрике данных Azure SSIS Integration Runtime in Azure Data Factory Применимо к: Applies to: SQL Server SQL Server (все поддерживаемые версии) SQL Server SQL Server (all supported versions) Azure-SSIS Integration Runtime в Фабрике данных Azure SSIS Integration Runtime in Azure Data Factory Azure-SSIS Integration Runtime в Фабрике данных Azure SSIS Integration Runtime in Azure Data Factory
В этом разделе показано, как подключаться к источникам данных PostgreSQL со страницы Выбор источника данных или Выбор назначения в мастере импорта и экспорта SQL Server. This topic shows you how to connect to a PostgreSQL data source from the Choose a Data Source or Choose a Destination page of the SQL Server Import and Export Wizard.
Подробные требования и необходимые условия для подключения к базе данных PostgreSQL выходят за рамки этой статьи Майкрософт. The detailed requirements and prerequisites for connecting to a PostgreSQL database are beyond the scope of this Microsoft article. В ней предполагается, что у вас уже установлено клиентское программное обеспечение PostgreSQL и вы можете успешно подключиться к целевой базе данных PostgreSQL. This article assumes that you already have PostgreSQL client software installed and that you can already connect successfully to the target PostgreSQL database. Для получения дополнительных сведений обратитесь к администратору базы данных PostgreSQL или к документации по PostgreSQL. For more info, consult your PostgreSQL database administrator or the PostgreSQL documentation.
Получение драйвера ODBC для PostgreSQL Get the PostgreSQL ODBC driver
Установка драйвера ODBC с помощью построителя стека Install the ODBC driver with Stack Builder
Запустите построитель стека, чтобы добавить драйвер ODBC для PostgreSQL (psqlODBC) в вашу установку PostgreSQL. Run Stack Builder to add the PostgreSQL ODBC driver (psqlODBC) to your installation of PostgreSQL.
Скачивание последней версии драйвера ODBC Or, download the latest ODBC driver
Или скачайте установщик Windows для последней версии драйвера ODBC для PostgreSQL (psqlODBC) прямо с этого FTP-сайта — https://www.postgresql.org/ftp/odbc/versions/msi/. Or, download the Windows installer for the latest version of the PostgreSQL ODBC driver (psqlODBC) directly from this FTP site — https://www.postgresql.org/ftp/odbc/versions/msi/. Извлеките содержимое ZIP-файла и запустите файл MSI. Extract the files from the .zip file and run the .msi file.
Подключение к PostgreSQL с помощью драйвера ODBC для PostgreSQL (psqlODBC) Connect to PostgreSQL with the PostgreSQL ODBC driver (psqlODBC)
Драйверы ODBC не приводятся в раскрывающемся списке источников данных. ODBC drivers aren’t listed in the drop-down list of data sources. Чтобы подключиться с помощью драйвера ODBC, сначала выберите поставщик данных .NET Framework для ODBC в качестве источника данных на странице Выбор источника данных или Выбор назначения. To connect with an ODBC driver, start by selecting the .NET Framework Data Provider for ODBC as the data source on the Choose a Data Source or Choose a Destination page. Этот поставщик служит оболочкой для драйвера ODBC. This provider acts as a wrapper around the ODBC driver.
Ниже показан экран, который появляется сразу после выбора поставщика данных .NET Framework для ODBC. Here’s the generic screen that you see immediately after selecting the .NET Framework Data Provider for ODBC.
Указываемые параметры (драйвер ODBC для PostgreSQL) Options to specify (PostgreSQL ODBC driver)
Параметры подключения для этого поставщика данных и драйвера ODBC одинаковы независимо от того, является ли PostgreSQL источником или назначением. The connection options for this data provider and ODBC driver are the same whether PostgreSQL is your source or your destination. Таким образом, на страницах Выбор источника данных и Выбор назначения мастера отображаются одинаковые параметры. That is, the options you see are the same on both the Choose a Data Source and the Choose a Destination pages of the wizard.
Чтобы подключиться к PostgreSQL с помощью драйвера ODBC для PostgreSQL, соберите строку подключения, используя указанные ниже параметры и их значения. To connect to PostgreSQL with the PostgreSQL ODBC driver, assemble a connection string that includes the following settings and their values. Полный формат строки подключения приведен после списка параметров. The format of a complete connection string immediately follows the list of settings.
Вы можете получить помощь в построении строки подключения. Get help assembling a connection string that’s just right. Кроме того, вместо указания строки подключения вы можете предоставить существующее имя DSN (имя источника данных) или создать новое. Or, instead of providing a connection string, provide an existing DSN (data source name) or create a new one. Дополнительные сведения об этих возможностях см. в разделе Подключение к источнику данных ODBC. For more info about these options, see Connect to an ODBC Data Source.
Драйвер Driver
Имя драйвера ODBC — PostgreSQL ODBC Driver(UNICODE) или PostgreSQL ODBC Driver(ANSI). The name of the ODBC driver — either PostgreSQL ODBC Driver(UNICODE) or PostgreSQL ODBC Driver(ANSI).
Server Server
Имя сервера PostgreSQL. The name of the PostgreSQL server.
порт. Port
Порт, используемый для подключения к серверу PostgreSQL. The port to use to connect to the PostgreSQL server.
База данных Database
Имя базы данных PostgreSQL. The name of the PostgreSQL database.
Uid и Pwd Uid and Pwd
Uid (идентификатор пользователя) и Pwd (пароль) для подключения. The Uid (user id) and Pwd (password) to connect.
Формат строки подключения Connection string format
Ниже приведен формат типичной строки подключения. Here’s the format of a typical connection string.
Ввод строки подключения Enter the connection string
Введите строку подключения в поле ConnectionString либо введите имя DSN в поле Dsn на странице Выбор источника данных или Выбор назначения. Enter the connection string in the ConnectionString field, or enter the DSN name in the Dsn field, on the Choose a Data Source or Choose a Destination page. После того как вы введете строку подключения, мастер проанализирует ее и отобразит отдельные свойства и их значения в списке. After you enter the connection string, the wizard parses the string and displays the individual properties and their values in the list.
В приведенном ниже примере используется следующая строка подключения: The following example uses this connection string.
Ниже показан экран, который появляется после ввода строки подключения. Here’s the screen that you see after entering the connection string.
Другие поставщики данных и дополнительные сведения Other data providers and more info
Сведения о подключении к PostgreSQL с помощью поставщика данных, не представленного в этом списке, см. в разделе Строки подключения PostgreSQL. For info about how to connect to PostgreSQL with a data provider that’s not listed here, see PostgreSQL connection strings. Этот сторонний сайт также содержит дополнительные сведения о поставщиках данных и параметрах подключения, описанных на этой странице. This third-party site also contains more info about the data providers and the connection parameters described on this page.
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 table named «postgres» owned by user «current logged in user name»
At the command line in your operating system, type the following command.
Debian based systems like Ubuntu :
Connect/login as root —
Redhat based systems like Centos / Fedora :
Connect/login as root —
Windows :
In windows, current user doesn’t matter
After accessing a PostgreSQL database, you can run SQL queries and more. Here are some common psql commands
- To view help for psql commands, type \?.
- To view help for SQL commands, type \h.
- To view information about the current database connection, type \conninfo.
- To list the database’s tables and their respective owners, type \dt.
- To list all of the tables, views, and sequences in the database, type \z.
- To exit the psql program, type \q.
psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, sent them to PostgreSQL, and see the query results.
Option | Description |
---|---|
-a —echo-all | Print all nonempty input lines to standard output as they are read. This is equivalent to setting the variable ECHO to all. |
-A —no-align | Switches to unaligned output mode. |
-c command —command=command | Specifies that psql is to execute one command string, command, and then exit. This is useful in shell scripts. Start-up files (psqlrc and |
/.psqlrc) are ignored with this option.
—dbname=dbname
—echo-queries
—echo-hidden
—field-separator=separator
—host=hostname
—html
—list
—log-file=filename
—no-readline
—output=filename
—port=port
—pset=assignment
—quiet
—record-separator=separator
—single-line
—tuples-only
—table-attr=table_options
—username=username
—set=assignment
—variable=assignment
—version
—no-password
—password
—expanded
—no-psqlrc
—field-separator-zero
—record-separator-zero
—single-transaction
—help
Connect to PostgreSQL database using pgAdmin GUI application
You can also connect to PostgreSQL database using pgAdmin GUI application. Connect to the database at localhost:5432 using the user name postgres and the password supplied.
Clicking on pgAdmin III following screen will come:
Now, double click on PostgreSQL 9.4 under the «Servers Groups». pgAdmin will ask you for a password. You have to supply the password for the postgres user for authentication.
Under the Database(s) on this server section, find the desired database and execute SQL queries: