Tableau connection
Tableau is a data analysis and visualization tool that supports seamless connections to local and cloud-based data sources, including spreadsheets and databases. This topic describes how to connect Tableau to AnalyticDB for PostgreSQL.
Connect to the database
-
Start Tableau.
-
On the Connect page, select Pivotal Greenplum Database.
-
On the sign-in page, enter your database connection information and click Log On.
NoteIf the connection fails, verify that your connection information is correct and that the IP address of the server running Tableau is in the database instance's whitelist. Then, try signing in again. For more information about adding an IP address to a whitelist, see Configure a whitelist.
Parameter
Description
Server
The public endpoint of your AnalyticDB for PostgreSQL database instance. For more information, see Manage public endpoints.
Port
The port number of the AnalyticDB for PostgreSQL database instance. The default is 3432.
Database
The name of your AnalyticDB for PostgreSQL database.
Username
Your AnalyticDB for PostgreSQL database username.
Password
Your AnalyticDB for PostgreSQL database password.
-
After you sign in, Tableau displays the data source page. The Connections area on the left panel shows the connected database instance, and the Database area shows the name of the current database. In the Table search box, search for and select a table, such as lineitem, then drag it to the canvas for analysis.
Analyze data
After connecting Tableau to your data, you can analyze tables and build reports.
For example, you can use the lineitem table from the TPC-H dataset. Open a new worksheet to visualize the data.
Drag YEAR(l_shipdate) to the Columns shelf, and drag l_shipmode and SUM(l_orderkey) to the Rows shelf. This generates a line chart that shows the annual trend of order amounts by shipping mode, such as AIR, FOB, MAIL, RAIL, REG AIR, and SHIP.
When you drag a dimension or measure to the worksheet, Tableau sends a query to AnalyticDB for PostgreSQL to retrieve data. For example, the query for the preceding chart is as follows:
BEGIN;declare "SQL_CUR0x7fdabf04ca00" cursor with hold for SELECT "lineitem"."l_linestatus" AS "l_linestatus",
"lineitem"."l_shipmode" AS "l_shipmode",
SUM("lineitem"."l_orderkey") AS "sum_l_orderkey_ok",
((CAST("lineitem"."l_shipdate" AS DATE) + CAST(TRUNC((-1 * (EXTRACT(DAY FROM "lineitem"."l_shipdate") - 1))) AS INTEGER) * INTERVAL '1 DAY') + CAST(TRUNC((-1 * (EXTRACT(MONTH FROM "lineitem"."l_shipdate") - 1))) AS INTEGER) * INTERVAL '1 MONTH') AS "tyr_l_shipdate_ok"
FROM "public"."lineitem" "lineitem"
GROUP BY 1,
2,
4;fetch 10000 in "SQL_CUR0x7fdabf04ca00"
Disable cursor mode
By default, Tableau uses cursor mode to fetch data from AnalyticDB for PostgreSQL. Example:
FETCH 10000 in “SQL_CUR0x7fe678049e00”
If you need to fetch a large amount of data and the Tableau server has enough memory to hold all the query results, you can disable cursor mode to improve performance.
To disable cursor mode:
-
Create a TDC file with the following configuration to disable cursor mode:
<?xml version='1.0' encoding='utf-8' ?> <connection-customization class='greenplum' enabled='true' version='4.3'> <vendor name='greenplum'/> <driver name='greenplum'/> <customizations> <customization name='odbc-connect-string-extras' value='UseDeclareFetch=0' /> </customizations> </connection-customization>Alternatively, to retrieve more data with each fetch, change the value of the 'Fetch' parameter. Use the following configuration:
<?xml version='1.0' encoding='utf-8' ?> <connection-customization class='greenplum' enabled='true' version='4.3'> <vendor name='greenplum'/> <driver name='greenplum'/> <customizations> <customization name='odbc-connect-string-extras' value='Fetch=100000' /> </customizations> </connection-customization> -
Save the file with the .tdc extension.
-
Move the TDC file to the Datasources directory.
For Tableau Desktop, move the file to Documents/My Tableau Repository/Datasources.
-
Restart Tableau for the changes to take effect.
Configure initial SQL
When connecting, you can use initial SQL to set specific parameters.
At the bottom of the Tableau sign-in page, click Initial SQL.... In the dialog box that appears, enter an SQL statement, such as 'set statement_mem = 1000000', and then click OK.
Do not end initial or custom SQL statements with a semicolon (;). Tableau encapsulates these statements during execution, so adding a semicolon causes a syntax error.