Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uniqueginun's avatar

Simple database query takes forever

Hello,

my app is connected to oracle database. everything was fine until suddenly every query start to take ages to run. even simplest queries.

for example

 select sysdate from dual

this query takes 0 seconds when I run it in sqldeveloper but this route takes about 10 seconds

Route::get('test', function () {
    $date = DB::select('select sysdate from dual');

    return $date;
});

what could be the issue!

0 likes
19 replies
Sinnbeck's avatar

Try using debugbar to see what is taking so long. How many records does it get?

uniqueginun's avatar

@Sinnbeck you mean the database? I am connecting to Oracle 11g database using yajra/laravel-oci8 package.

Tray2's avatar

@uniqueginun This sounds more like it takes time to connect to the database rather than the query it self. Are you using ldap, tns or something else for the database name lookup?

uniqueginun's avatar

@Tray2 btw I tried to test the database connection process by this code

Route::get('test', function () {
    try {
        DB::connection()->getPdo();
        if(DB::connection()->getDatabaseName()){
            dd("Yes! Successfully connected to the DB: " . DB::connection()->getDatabaseName());
        }else{
            dd("Could not find the database. Please check your configuration.");
        }
    } catch (\Exception $e) {
        dd("Could not connect to the database.  Please check your configuration. error:" . $e );
    }
});

this route took milliseconds to respond and it displayed my connection info

MohamedTammam's avatar

Is that a valid syntax?

shouldn't it be like this?

$date = DB::table('dual')->select('sysdate')->get();

And what happen if you run the query directly in the database, does it take long time?

Try to run the query against Explain to see what's happening.

uniqueginun's avatar

@MohamedTammam yes it is a valid syntax you can run raw queries. when I run queries directly from database it is super fast. the app itself is fast when no database query is involved

Please or to participate in this conversation.