Category Archives: Databases - Page 5

Oracle: Export tables with the exp command and a parfile

This is an example of an export of selected tables with the Oracle DB command exp:

Parfile:

BUFFER=100000
TABLES=(table1,table2,table3)
FILE=/path/to/exportfile.dmp
LOG=/path/to/logfile.log

Let’s name this file ‘export.conf’

Command:

exp <user>/<password>@<sid> PARFILE=export.conf

This will export all data needed to recreate the tables: table1, table2 and table3 into exportfile.dmp. This file can later be used with the imp command to restore the tables

To see more options of the exp command try:

exp help=y

This will show you a list of commands and settings

SQLPlus: Dump table data to csv file

Since this is quite a cumbersome operation (in contrast to for example with MySQL) I have put together a script to modify and use every time I need to dump some table data to a CSV file.
NOTE: This only works with text and simple number fields. More complex field types will just come out truncated or as gibberish.

SET echo off
SET feedback off
SET linesize 100
SET pagesize 0
SET sqlprompt ''
SET trimspool on
SPOOL filename.csv

SELECT field1 || ',' || field2 || ',' || field3 FROM tablename;

SPOOL off
exit

As you can see the trick is to turn off any extra output and to use the string concatenation operator|,|to insert commas (or any separator you want) between the fields.

The SPOOL command opens a file and dump all output made until the SPOOL off command

To run the script use:

sqlplus <user>/<password>@<SID> @scriptname.sql

Tested with SQL*Plus: Release 10.1.0.2.0

PCC v11 GUI all messed up

This happened a few days after a new installation I did on Windows Server 2003 (Pervasive Server 6 user v11, DataExchange v4) and one XP workstation (Pervasive Workgroup Engine v11, DataExchange v4). The first days everything looked and worked as it should. PCC opens and shows all tables and synchronizations. But one day PCC started taking a long time starting and the GUI was all messed up, see screenshot

PCC v11 GUI at start

PCC v11 GUI all messed up

This view is the only one I can access. I could not open other panes and when trying to ‘Initiate replication’ the GUI reported that no Engine was running (which it was – replication still worked when I checked from the workstations synchronizing with the server)

So how do we fix it? The solution for us was to force PCC to reinitialize. Here is what we did:
1. Open the file pcc.ini in a text viewer, normally at: “C:Program Files\Pervasive Software\PSQL\bin\pcc.ini”
2. Check the ‘Data’ section in the pcc.ini. Here is a path to the PCC working directory
3. Go to the location of the PCC working directory and rename it, eq from workspace to workspace-old
4. Start PCC

For us this fix is not always permanent – it happens that we have to do this again after a few months on the Windows Server 2003. The XP machine has so far never needed this fix again