A client has outgrown their Access database, and now I need to convert it to PostgreSQL. I don't have a lot of Access experience, so at first blush it seems like the best solution is to just export the data using text files or something.
Does anyone have any good suggestions for an easy way to get the DDL and data out of Access and into something real?
In Microsoft Access, you can connect to your PostgreSQL data either by importing it or creating a table that links to the data. Devart ODBC drivers support all modern versions of Access. It is assumed that you have already installed and configured a DSN for ODBC driver for PostgreSQL.
In such situation all you need is to convert Access To SQL. Luckily, Microsoft provides an upsizing wizard in access 2010 that makes it easy to convert your database. As, this tutorial discusses the process of converting or migrating Access database to SQL server.
Switch databases in PostgreSQL with `\connect`Once you are in the Postgres terminal, you enter using the psql command, you can switch databases with \connect <db_name> command or with the shorter \c <db_name> . In order to list the available databases you use the \l or \list meta-command.
Based on http://www.postgresonline.com/journal/archives/24-Using-MS-Access-with-PostgreSQL.html but updated for Access 2019 with more details:
Install the PostgreSQL ODBC drivers.
External Data > New Data Source > From Other Sources > ODBC Database. The keyboard shortcut for this is Alt > X > N1 > T > C.
Choose Link to the data source by creating a linked table, and press OK.
Next to DSN Name, click New...
Choose PostgreSQL Unicode if your databases is UTF-8 or a non Latin Encoding. Choose PostgreSQL ANSI if your database encoding is SQL_ASCII, EUC_JP, BIG5, Shift-JIS, or a LATIN character set. Databases made from Access 2000 or later are in UTF-8. Choose the 64-bit version if Access is 64-bit. Click Next >.
As the dialog says, "Type in the name of the file data source you want to save the connection to. Or, find the location to save to by clicking Browse." Click Next >. Click Finish.
Fill in the fields Database, Server, Port, User Name, and Password.
Click Connection and uncheck Bools as char.
Click Page 2 and check True is -1, and uncheck Updatable Cursors. Click OK. Click OK.
If you get an error that says "A connection could not be made using the file data source parameters entered", open ODBC Data Sources (64-bit) from the Start menu (or ODBC Administrator from Control Panel for Windows 7 or earlier), click Add..., choose PostgreSQL Unicode(x64), click Finish, enter the details for your database, and click Test.
- Now select the tables you want and click Save Password. If you are missing primary keys on tables, Access will prompt you for what fields or set of fields you would like to use as the primary key. This doesn't make any structural changes to the actual table, but in the linked structure, Access will pretend this is the primary key and use that accordingly for table updates and such. This is particularly useful for views where the concept of primary keys does not exist and you want your updateable views to be updateable from Access. If you click OK or Cancel to the question without picking a set of fields, that table will be marked as readonly, which is the desired behavior for a lot of reporting views.
To export data from an Access table to PostgreSQL:
Select the table.
Rename the table to what you want it to be named.
- Make sure the default schema of the user you are using in Postgres, is the schema you want to export the data to.
- One gotcha here is that PostgreSQL will maintain the casing of the fields in the table and the table name, so it's best to rename all your fields to lowercase first so you don't have to be quoting them every time you use them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With