Sybase SQL Anywhere 10 - Logging SQL Statements - sqlanywhere

Does anyone know of a mechanism in Sybase ASA 9 / Sybase SQL Anywhere 10 to log the SQL statements that it executes?
I have a web application that is misbehaving due to some apparently missing data, but everything looks fine.
If we were able to log the offending statement we could probably get things sorted.

Take a look at the -zr server switch. You can also look at the sa_server_option system procedure to change the setting while the server is running.

Related

Graphical query designer for PostgreSQL

I have for years used MS Access and its query tool that is used for making queries. This tool is so good that I have never been forced to do very much SQL programming myself. The query tool has done all the work.
However, now I have started using Postgres and the Graphical Query Builder in pgAdmin. It seems that the Graphical Query Builder is rather primitive: It cannot be used if you need an aggregate function like SUM or COUNT.
Is this really correct?
Does anybody know a better graphical query builder for PostgreSQL?
Until now I have 'solved' the problem by linking MS Access to the Postgres database through ODBC and used MS Access' query tool to generate SQL commands which I then copy into pgAdmin's Graphical Query Builder - and edit the SQL commands until everything is correct.
SQL Maestro has a query designer, although it is PC only, AFAIK
http://www.sqlmaestro.com/products/postgresql/maestro/screenshots/getting_started/visual_query_builder/
EMS SQL Manager also has a query designer
http://www.sqlmanager.net/en/products/postgresql/manager/screenshots
Try SQLeo, its free and has a specific feature (autosavepoint) to prevent
ERROR: current transaction is aborted, commands ignored until end of transaction block.
Try a browser-based query builder for PostgreSQL called Skyvia. And you don’t have to worry about which operating system it works. It works where a browser exists. Simply make a connection to your PostgreSQL database and start building your queries. See a sample below.
Note that you can still switch between SQL code and query builder if you want to, just like in MS Access. Get the details here.

How to see the actual sql statements executed by POSTGRES?

I want to log the actual sql statements executed against a POSTGRES instance. I am aware that I can enable logging of the sql statements. Unfortunately, this doesn't log the actual sql, but rather a parsed version, with certain parameters stripped out and listed separately.
Is there a tool for reliably reconstituting this output into executable sql statements?
Or is there a way of intercepting the sql that is send to the postgres instance, such that that sql can be logged?
We want to be able to replay these sql statements against another database.
Thanks for your help!
Actually, PostgreSQL does log exactly the SQL that got executed. It doesn't strip parameters out. Rather, it doesn't interpolate them in, it logs what the application sent, with bind parameters separate. If your app sends insert into x(a,b) values ($1, $2) with bind params 42 and 18, that's what gets logged.
There's no logging option to interpolate bind parameters into the query string.
Your last line is the key part. You don't want logging at all. You're trying to do statement based replication via the logs. This won't work well, if at all, due to volatile functions, the search_path, per-user settings, sequence allocation order/gap issues, and more. If you want replication don't try to do it by log parsing.
If you want to attempt statement-based replication look into PgPool-II. It has a limited ability to do so, with caveats aplenty.
Via setting log_statement to all on postgresql.conf. See the documentation for runtime-config-logging

How to find Who did some query on the database and when?

I have a SQL Server 2008 R2 with a database in it.
How to find a certain query that was executed and from what IP ?
I have tried to go through the transaction logs but I cant understand nothing there.
You should use SQL Server Profiler. It's usually installed by default - look in the SQL Server folder on the Start Menu. When you open it, start a new trace and select the database. In the Trace Properties dialog choose the TSQL template. This will then record all the queries running on the database, along with a whole lot of other stuff. It's not massively easy to track stuff down in here, but look for the BatchStarting events to find the SQL that gets run. Then you should run the procedure sp_who2 on the database so you can match up SPIDs in the profiler to logins.

SQL Server 2008 R2 Debug with user

I need to figure out a way to run under debug in SQL Server Management Studio 2008 R2. But I am given some restrictions that I cannot find the workaround for:
The user needs to be owner of a specific schema.
For that reason, the user cannot have the SysAdmin privilege. The reason for this is we already have many Stored Procedures where we do not specify the name of the Schema for the SQL Queries.
Since the user needs to have SysAdmin privilege, this conflicts with the first requirement as you cannot modify the DEFAULT_SCHEMA for sysadmins.
As far as I know, the only way to debug in SQL Server 2008 is to be given a SysAdmin privilege as this is how M$FT designed their software. What could be a possible workaround for this?
I understand that the recommended answer would be somewhere along the line of change how we wrote the SP or to consider redesigning the database design but sadly, this is not an option.
Please help!
By run under debug do you mean you want to debig stored procedures interactively using the T-SQL debugger?
If you are having problems getting this running, and your objective is to debug your code, you could also use SQL Profiler to observe exactly what is being executed inside your stored procedure. It of course will not support break points and start/stop but it will let you observe what is being executed.
Taken from MSDN: Run the Transact-SQL Debugger
We recommend that Transact-SQL code be debugged on a test server, not
a production server, for the following reasons: Debugging is a highly
privileged operation. Therefore, only members of the sysadmin fixed
server role are allowed to debug in SQL Server. Debugging sessions
often run for long periods of time while you investigate the
operations of several Transact-SQL statements. Locks, such as update
locks, that are acquired by the session might be held for extended
periods, until the session is ended or the transaction committed or
rolled back.
If you have concerns you may want to report your wish at microsoft connect site:
http://connect.microsoft.com/sqlserver

Progress ABL procedure to SQL Insert

We have a software solution that involves syncing some data between a Progress database and SQL server. Unfortunately, we do not have any Progress gurus in house, so I'm working kinda blind here and would welcome any advice that is on offer.
For the workflow that is already in place, what would work very well for us is the ability to do an external call to insert a row into an SQL database from an within ABL procedure's 'for each' loop.
Is anyone able to direct me to any code snippets or articles that might help me achieve this?
Many thanks,
In case your SQL database is MS SQL Server, you might want to have a look at OpenEdge DataServer for Microsoft SQL Server (web.progress.com/en/openedge/dataserver-microsoft.html, documentation.progress.com/output/OpenEdge102b/pdfs/dmsql/dmsql.pdf).
The DataServer provides you with ABL access to a non-Progress database so you can use standard Progress statements, e.g. CREATE to add new records or FOR EACH to retrieve query results.
OpenEdge DataServers are also available for Oracle (using Oracle Call Interface), DB2 and Sybase (using ODBC). The DataServer for MS SQL Server uses ODBC behind the scenes as well. web.progress.com/docs/datasheets/openedge/openedge_dataservers.pdf
You dont need the dataserver, connection with ADODB works fine in ABL, you can even call stored-procedures with the command object, the user you connect with will have to be granted EXEC rigths on the SQL-Server to do that.
I'm not a Progress guru, but I did do some work in it for awhile. AFAIK there is no way to have ABL code connect to a non-Progress database (part of that whole vendor lock-in strategy Progress Corp. leverages).
Your best bet is probably to have the ABL code serialize the records to XML, and use something like ActiveMQ (or even a plain socket or named pipe/FIFO depending on your setup) to send them to a program written in a more capable language to do the SQL insert.