Feeds:
Posts
Comments

Archive for the ‘Databases’ Category

Often RDS users trying to import data face this error when they try to create triggers:

ERROR 1419 (HY000) at line 49: You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)

The reason for this is that the default DB parameter group doesn’t have the privileges set to create and insert triggers into the database. To get rid of this error, do the following:

  1. Obtain RDS CLI tools from AWS website here, and follow the installation steps.
  2. On your terminal (or command line) create a new parameter group (since we can’t directly modify the default parameter group)
    rds-create-db-parameter-group allow-triggers --db-parameter-group-family mysql5.5 --description "parameter group to allow triggers"
  3. Now modify the parameter group created just now
    rds-modify-db-parameter-group allow-triggers --parameters "name=log_bin_trust_function_creators, value=true, method=immediate"
  4. Apply the new group to the database
    rds-modify-db-instance --db-instance-identifier instance-name --db-parameter-group-name allow-triggers --apply-immediately
  5. Finally, you will need to restart your RDS instance.

After running the above you should be able to import your schema/data and create triggers without problem. In case you receive the following error while using mysqldump

ERROR 1227 (42000) at line 2492: Access denied; you need (at least one of) the SUPER privilege(s) for this operation.

then, the problem is with the definer statement in your trigger. Change it from

DEFINER=user_a@localhost

to something like

DEFINER=correctuser@ip

Read Full Post »

So the other day I had to back up all database objects for an Oracle instance i manage and I was looking for some tool that would help me generate DDL for each object in a separate SQL file.

A quick Google search revealed I could backup DDL using TOAD (full version), DB Solo and RazorSQL. I use DBArtisan at work and my organization doesn’t want to move to TOAD yet. I have used DB Solo in the past and I have liked the clean and light interface and the quick ability to back up DDL but I just couldn’t use it this time because I had already expired my trial version and didn’t have enough time to get the folks sign off on purchase of a license (which is not very expensive). So I decided to try RazorSQL, but was disappointed because it dumps all objects in one single SQL file. Also, when I tried to back up stored procedures (over 5000 of them), the program refused to copy.

Out of luck and exhausted, I remembered the good old DBMS_METADATA commands. I quickly created a new directory entry in the database for the location where i wanted to dump my DDL, and executed a procedure that I wrote to perform the DDL backup.

Here are the steps I followed: (one can use SQL PLUS or any DB tool he wants)

–create a new directory in all_directories table. This is important to avoid ORA-29280 invalid_path execption.

CREATE OR REPLACE DIRECTORY BACKUP_DIR AS 'E:\DATA_BKP';

–also grant permissions to everyone to read, write (maybe restricted based on your requirement).

GRANT READ,WRITE ON BACKUP_DIR TO PUBLIC;

–the stored procedure for DDL backup
–note that we are reading from USER_OBJECTS data dictionary, this way it exports only the current user’s objects.
–to export all objects, execute procedure as sys or sysdba and use the table ALL_OBJECTS instead.

CREATE OR REPLACE PROCEDURE	EXPORT_DDL
AS
	V_DDL_CLOB  CLOB;
	VPATH VARCHAR2(255);
BEGIN
	FOR C IN (SELECT OBJECT_NAME, OBJECT_TYPE
             FROM USER_OBJECTS
             WHERE OBJECT_TYPE IN ('TABLE','VIEW','FUNCTION','PROCEDURE','PACKAGE','PACKAGE_BODY'))
	LOOP
		V_DDL_CLOB := DBMS_METADATA.GET_DDL(C.OBJECT_TYPE, C.OBJECT_NAME, 'EAGLE');
		DBMS_XSLPROCESSOR.CLOB2FILE(V_DDL_CLOB, 'BACKUP_DIR', C.OBJECT_TYPE || '_' || C.OBJECT_NAME||'.SQL');
	END LOOP;
END;
/

EXEC EXPORT_DDL;

Now that was simple, wasn’t it? 🙂

Read Full Post »