ablog

不器用で落着きのない技術者のメモ

SQL Workbench/J のコンソールモードを使う

環境

インストール

  • SQL Workbench/J -  Downloads で [Download generic package for all systems] をダウンロードする。*1
  • Workbench-Build122.zip を解凍して任意のフォルダに置く。

設定

  • GUIで起動する。
$ cd Workbench-Build122
$ sh ./sqlworkbench.sh

コンソールモードで接続する

$ cd Workbench-Build122
$ sh ./sqlwbconsole.sh -profile=Redshift ★GUI で設定したプロファイル名を指定
readlink: illegal option -- f
usage: readlink [-n] [file ...]

SQL Workbench/J (122) console interface started.
Enter exit to quit.
Enter WbHelp for a list of SQL Workbench/J specific commands
Config directory: /Users/******/.sqlworkbench

Connection to "User=master, Schema=public, URL=jdbc:redshift://***.***.ap-northeast-1.redshift.amazonaws.com:5439/mydb" successful

master@public> select * from PG_TABLE_DEF limit 10;

schemaname | tablename                | column       | type           | encoding | distkey | sortkey | notnull
-----------+--------------------------+--------------+----------------+----------+---------+---------+--------
pg_catalog | padb_config_harvest      | name         | character(136) | lzo      | false   |       0 | true
pg_catalog | padb_config_harvest      | harvest      | integer        | lzo      | false   |       0 | true
pg_catalog | padb_config_harvest      | archive      | integer        | lzo      | false   |       0 | true
pg_catalog | padb_config_harvest      | directory    | character(500) | lzo      | false   |       0 | true
pg_catalog | pg_aggregate             | aggfnoid     | regproc        | none     | false   |       0 | true
pg_catalog | pg_aggregate             | aggtransfn   | regproc        | none     | false   |       0 | true
pg_catalog | pg_aggregate             | aggfinalfn   | regproc        | none     | false   |       0 | true
pg_catalog | pg_aggregate             | aggtranstype | oid            | none     | false   |       0 | true
pg_catalog | pg_aggregate             | agginitval   | text           | none     | false   |       0 | false
pg_catalog | pg_aggregate_fnoid_index | aggfnoid     | regproc        | none     | false   |       0 | false

(10 Rows)
SELECT executed successfully

master@public>
master@public> \q
$

補足

  • sqlwbconsole.sh を見ると、起動時にオプションで workbench.console.SQLConsole を指定している。
$ cat sqlwbconsole.sh
#!/bin/sh
# Start SQL Workbench/J in console mode

SCRIPT_PATH="$(dirname "$(readlink -f "$0")")"

JAVACMD="java"

if [ -x "$SCRIPT_PATH/jre/bin/java" ]
then
  JAVACMD="$SCRIPT_PATH/jre/bin/java"
elif [ -x "$WORKBENCH_JDK/bin/java" ]
then
  JAVACMD="$WORKBENCH_JDK/bin/java"
elif [ -x "$JAVA_HOME/jre/bin/java" ]
then
  JAVACMD="$JAVA_HOME/jre/bin/java"
elif [ -x "$JAVA_HOME/bin/java" ]
then
  JAVACMD="$JAVA_HOME/bin/java"
fi

cp=$SCRIPT_PATH/sqlworkbench.jar
cp=$cp:$SCRIPT_PATH/dom4j-1.6.1.jar
cp=$cp:$SCRIPT_PATH/poi-ooxml-schemas.jar
cp=$cp:$SCRIPT_PATH/poi-ooxml.jar
cp=$cp:$SCRIPT_PATH/poi.jar
cp=$cp:$SCRIPT_PATH/stax-api-1.0.1.jar
cp=$cp:$SCRIPT_PATH/resolver.jar
cp=$cp:$SCRIPT_PATH/serializer.jar
cp=$cp:$SCRIPT_PATH/simple-odf.jar
cp=$cp:$SCRIPT_PATH/ext/*

$JAVACMD -Djava.awt.headless=true \
         -Xmx1024m \
         -Dvisualvm.display.name=SQLWorkbench \
         -cp $cp workbench.console.SQLConsole "$@"

*1:[Download package for MacOS] ではない